cudno ponasanje PIC-a - Ko je tu lud???

Rasprava o PIC mikrokontrolerima, PIC projekti i drugo vezano za PIC-eve...

Moderators: pedja089, stojke369, [eDo], trax

Post Reply
zelja
Pocetnik na forumu
Pocetnik na forumu
Posts: 25
Joined: 21-02-2005, 14:05

cudno ponasanje PIC-a - Ko je tu lud???

Post by zelja »

Pozdrav,


Imam PIC 16F628, pravim program u mikroBasicu, programiram ga sa ICprogom

Ploca ima 5 ulaza (RA7, 6, 5, 4, 3) i 4 izlaza(RB7, 6, 5, 4). U programu koristim procedure kako bi kontrolirao tijek izvodjenja programa.

Nakon 4 prve procedure sve je ok. Ali zadnja mi nije nikako htjela okinuti.

Svasta sam radio sa programom. mijenjao, pokusavao ali nece.

I Pic se poceo cudno ponasati. Poceo mi je slati izlaze koje mu uopce nisam zadao.

Isao sam vratiti stari program koji mi je radio do 4 koraka ali i on nije vise bio dobar????

To mi nikako nije bilo jasno. Pa sam ga prebrisao da ne bi bilo zaostataka nekih u njemu. I nije pomoglo.

Dogadja li se to ikome? Jednostavno Pic ne radi sto treba. Mislio bi da je basic programa. Ali jutros mi radi a poslije ne. Potpuno isti program???
buco

Post by buco »

Mislim da ti je sumlja na krivom mijestu . MCU te sigurno ne zeza !!! Provijeri config bitove , iako mi nije jasno kako to mislis radi pa ne radi ?
Ako je to bas tako provijeri spojeve svih elemenata na plocici gdije je MCU . Ako mozes postavit u asembleru taj tvoj program , mogao bi pomoc oko trazenja greske u programu , ako nisu spojevi ili nesto gore navedeno.
Mozda nebi bilo lose da si nabavis diassembler dobro dodje u takvim situacijama , jer tocno znas sto je compiller generirao kao izvrsni kod.Pa onda lako provijeris jel tamo neka "greska" .
zelja
Pocetnik na forumu
Pocetnik na forumu
Posts: 25
Joined: 21-02-2005, 14:05

Post by zelja »

Program je predug za brzo pregledavanje. Ali evo postam ti ga. ALi prije toga evo programa u Basicu. Puno je laksi za snalazenje

program cistilica


dim ukljuci as byte
dim brojac as byte
dim zastavica as byte

sub procedure korakPrvi

'While brojac<0
'pali Q1, ceka pola sekunde i pali Q2
PORTB.7 = 1
delay_ms(500)
PORTB.6 = 1 'Q2
delay_ms(500)
'Wend

end sub

sub procedure korakDrugi

While brojac<1

If Button(PORTA, 6, 2, 0) Then ' reset Q2 ako je pritisnut
PORTB.6 = 0 'Q2
brojac = 1
End If
Wend

end sub

sub procedure korakTreci

While brojac<2
'I3 = RA5
If Button(PORTA, 5, 2, 0) Then ' pali Q3
PORTB.5 = 1 'Q3
brojac = 2
End If
Wend

end sub

sub procedure korakCetvrti

While brojac<3
'I4 = RA4
If Button(PORTA, 4, 2, 0) Then ' pali Q4 - mali klip i gasi Q3, veliki klip koji se vraca gore -

PORTB.4 = 1 'q4
PORTB.5 = 0 'q3
brojac=3
End If
Wend

end sub

sub procedure korakPeti

While brojac<4
'I5 = RB1
If Button(PORTA, 3, 2, 0) Then ' resetira Q4 i Q1
PORTB.4 = 0 'Q4
PORTB.7 = 0 'Q1
brojac=4
End If
Wend

end sub

sub procedure korakSesti

While brojac<5

zastavica = TestBit(PORTA, 7)

If zastavica=0 Then ' profil je izvucen, vracaj se u glavnu petlju i zavrsi
brojac=5
End If
Wend

end sub

main:

TRISA = %11111100
PORTA = 0
TRISB = %00000000
PORTB = 0 ' begins with last led on

ukljuci=0
brojac=0
zastavica=1


While true

If Button(PORTA, 7, 2, 0)Then ' dodati u petlju izvrsavanje ako su ova dva aktivna
'and Button(PORTA, 1, 4, 0)
korakPrvi 'pali Q1 i Q2
korakDrugi 'ceka da freza dodje do I2 i onda resetira Q2
korakTreci 'ceka da se freza vrati, kad se vratila onda pokrece Q3
korakCetvrti ' pali Q4 - mali klip i gasi Q3, veliki klip koji se vraca gore
korakPeti 'kad dodje u I3 resetira Q4 i Q1
korakSesti 'ceka da se izvuce profil, kad se izvuce, vraca se u glavnu petlju
End If

Wend

end.


$0000 $2985 GOTO cistilica_main
$0004 $ delays_delay_500us:
$0004 $30A5 MOVLW 165
$0005 $1303 BCF STATUS,RP1
$0006 $1283 BCF STATUS,RP0
$0007 $00F0 MOVWF STACK_0
$0008 $ delays_L_4:
$0008 $0BF0 DECFSZ STACK_0, F
$0009 $2808 GOTO delays_L_4
$000A $0000 nop
$000B $0000 nop
$000C $0008 RETURN
$000D $ button_button:
$000D $1303 BCF STATUS,RP1
$000E $1283 BCF STATUS,RP0
$000F $01A3 CLRF button_button_local_result
$0010 $0824 MOVF button_button_param_port, W
$0011 $0084 MOVWF FSR
$0012 $3001 MOVLW 1
$0013 $00F1 MOVWF STACK_1
$0014 $0825 MOVF button_button_param_pin, W
$0015 $00F2 MOVWF STACK_2
$0016 $ button_L_3:
$0016 $3000 MOVLW 0
$0017 $0272 SUBWF STACK_2, W
$0018 $1903 BTFSC STATUS, Z
$0019 $281E GOTO button_L_4
$001A $0DF1 RLF STACK_1, F
$001B $1071 BCF STACK_1, 0
$001C $0BF2 DECFSZ STACK_2, F
$001D $2816 GOTO button_L_3
$001E $ button_L_4:
$001E $0824 MOVF button_button_param_port, W
$001F $0084 MOVWF FSR
$0020 $0800 MOVF INDF, W
$0021 $05F1 ANDWF STACK_1, F
$0022 $3001 MOVLW 1
$0023 $1D03 BTFSS STATUS, Z
$0024 $00F1 MOVWF STACK_1
$0025 $0827 MOVF button_button_param_activestate, W
$0026 $0271 SUBWF STACK_1, W
$0027 $1D03 BTFSS STATUS, Z
$0028 $282C GOTO button_L_1
$0029 $ button_L_0:
$0029 $30FF MOVLW 255
$002A $00F2 MOVWF STACK_2
$002B $282D GOTO button_L_5
$002C $ button_L_1:
$002C $01F2 CLRF STACK_2
$002D $ button_L_5:
$002D $30FF MOVLW 255
$002E $0272 SUBWF STACK_2, W
$002F $1D03 BTFSS STATUS, Z
$0030 $2869 GOTO button_L_7
$0031 $ button_L_6:
$0031 $ button_L_8:
$0031 $01F2 CLRF STACK_2
$0032 $0826 MOVF button_button_param_time, W
$0033 $0272 SUBWF STACK_2, W
$0034 $1803 BTFSC STATUS, C
$0035 $2839 GOTO button_L_10
$0036 $ button_L_9:
$0036 $30FF MOVLW 255
$0037 $00F1 MOVWF STACK_1
$0038 $283A GOTO button_L_11
$0039 $ button_L_10:
$0039 $01F1 CLRF STACK_1
$003A $ button_L_11:
$003A $30FF MOVLW 255
$003B $0271 SUBWF STACK_1, W
$003C $1D03 BTFSS STATUS, Z
$003D $2846 GOTO button_L_13
$003E $ button_L_12:
$003E $2004 CALL delays_delay_500us
$003F $2004 CALL delays_delay_500us
$0040 $0826 MOVF button_button_param_time, W
$0041 $00F2 MOVWF STACK_2
$0042 $03F2 DECF STACK_2, F
$0043 $0872 MOVF STACK_2, W
$0044 $00A6 MOVWF button_button_param_time
$0045 $2831 GOTO button_L_8
$0046 $ button_L_13:
$0046 $0824 MOVF button_button_param_port, W
$0047 $0084 MOVWF FSR
$0048 $3001 MOVLW 1
$0049 $00F1 MOVWF STACK_1
$004A $0825 MOVF button_button_param_pin, W
$004B $00F2 MOVWF STACK_2
$004C $ button_L_17:
$004C $3000 MOVLW 0
$004D $0272 SUBWF STACK_2, W
$004E $1903 BTFSC STATUS, Z
$004F $2854 GOTO button_L_18
$0050 $0DF1 RLF STACK_1, F
$0051 $1071 BCF STACK_1, 0
$0052 $0BF2 DECFSZ STACK_2, F
$0053 $284C GOTO button_L_17
$0054 $ button_L_18:
$0054 $0824 MOVF button_button_param_port, W
$0055 $0084 MOVWF FSR
$0056 $0800 MOVF INDF, W
$0057 $05F1 ANDWF STACK_1, F
$0058 $3001 MOVLW 1
$0059 $1D03 BTFSS STATUS, Z
$005A $00F1 MOVWF STACK_1
$005B $0827 MOVF button_button_param_activestate, W
$005C $0271 SUBWF STACK_1, W
$005D $1D03 BTFSS STATUS, Z
$005E $2862 GOTO button_L_15
$005F $ button_L_14:
$005F $30FF MOVLW 255
$0060 $00F2 MOVWF STACK_2
$0061 $2863 GOTO button_L_19
$0062 $ button_L_15:
$0062 $01F2 CLRF STACK_2
$0063 $ button_L_19:
$0063 $30FF MOVLW 255
$0064 $0272 SUBWF STACK_2, W
$0065 $1D03 BTFSS STATUS, Z
$0066 $2869 GOTO button_L_21
$0067 $ button_L_20:
$0067 $30FF MOVLW 255
$0068 $00A3 MOVWF button_button_local_result
$0069 $ button_L_21:
$0069 $ button_L_16:
$0069 $ button_L_7:
$0069 $ button_L_2:
$0069 $0008 RETURN
$006A $ cistilica_korakprvi:
$006A $1303 BCF STATUS,RP1
$006B $1283 BCF STATUS,RP0
$006C $1786 BSF PORTB, 7
$006D $3003 MOVLW 3
$006E $00F0 MOVWF STACK_0
$006F $30FF MOVLW 255
$0070 $00F1 MOVWF STACK_1
$0071 $30FF MOVLW 255
$0072 $00F2 MOVWF STACK_2
$0073 $0BF0 DECFSZ STACK_0, F
$0074 $2876 GOTO $+2
$0075 $287D GOTO $+8
$0076 $0BF1 DECFSZ STACK_1, F
$0077 $2879 GOTO $+2
$0078 $287C GOTO $+4
$0079 $0BF2 DECFSZ STACK_2, F
$007A $2879 GOTO $-1
$007B $2876 GOTO $-5
$007C $2873 GOTO $-9
$007D $308C MOVLW 140
$007E $00F0 MOVWF STACK_0
$007F $30FF MOVLW 255
$0080 $00F1 MOVWF STACK_1
$0081 $0BF0 DECFSZ STACK_0, F
$0082 $2884 GOTO $+2
$0083 $2887 GOTO $+4
$0084 $0BF1 DECFSZ STACK_1, F
$0085 $2884 GOTO $-1
$0086 $2881 GOTO $-5
$0087 $30A1 MOVLW 161
$0088 $00F0 MOVWF STACK_0
$0089 $0BF0 DECFSZ STACK_0, F
$008A $2889 GOTO $-1
$008B $0000 nop
$008C $1706 BSF PORTB, 6
$008D $3003 MOVLW 3
$008E $00F0 MOVWF STACK_0
$008F $30FF MOVLW 255
$0090 $00F1 MOVWF STACK_1
$0091 $30FF MOVLW 255
$0092 $00F2 MOVWF STACK_2
$0093 $0BF0 DECFSZ STACK_0, F
$0094 $2896 GOTO $+2
$0095 $289D GOTO $+8
$0096 $0BF1 DECFSZ STACK_1, F
$0097 $2899 GOTO $+2
$0098 $289C GOTO $+4
$0099 $0BF2 DECFSZ STACK_2, F
$009A $2899 GOTO $-1
$009B $2896 GOTO $-5
$009C $2893 GOTO $-9
$009D $308C MOVLW 140
$009E $00F0 MOVWF STACK_0
$009F $30FF MOVLW 255
$00A0 $00F1 MOVWF STACK_1
$00A1 $0BF0 DECFSZ STACK_0, F
$00A2 $28A4 GOTO $+2
$00A3 $28A7 GOTO $+4
$00A4 $0BF1 DECFSZ STACK_1, F
$00A5 $28A4 GOTO $-1
$00A6 $28A1 GOTO $-5
$00A7 $30A1 MOVLW 161
$00A8 $00F0 MOVWF STACK_0
$00A9 $0BF0 DECFSZ STACK_0, F
$00AA $28A9 GOTO $-1
$00AB $0000 nop
$00AC $0008 RETURN
$00AD $ cistilica_korakdrugi:
$00AD $ cistilica_L_0:
$00AD $3001 MOVLW 1
$00AE $1303 BCF STATUS,RP1
$00AF $1283 BCF STATUS,RP0
$00B0 $0220 SUBWF main_global_brojac, W
$00B1 $1803 BTFSC STATUS, C
$00B2 $28B6 GOTO cistilica_L_2
$00B3 $ cistilica_L_1:
$00B3 $30FF MOVLW 255
$00B4 $00F1 MOVWF STACK_1
$00B5 $28B7 GOTO cistilica_L_3
$00B6 $ cistilica_L_2:
$00B6 $01F1 CLRF STACK_1
$00B7 $ cistilica_L_3:
$00B7 $30FF MOVLW 255
$00B8 $0271 SUBWF STACK_1, W
$00B9 $1D03 BTFSS STATUS, Z
$00BA $28CF GOTO cistilica_L_5
$00BB $ cistilica_L_4:
$00BB $3005 MOVLW PORTA
$00BC $00A4 MOVWF button_button_param_port
$00BD $3006 MOVLW 6
$00BE $00A5 MOVWF button_button_param_pin
$00BF $3002 MOVLW 2
$00C0 $00A6 MOVWF button_button_param_time
$00C1 $01A7 CLRF button_button_param_activestate
$00C2 $200D CALL button_button
$00C3 $30FF MOVLW 255
$00C4 $1303 BCF STATUS,RP1
$00C5 $1283 BCF STATUS,RP0
$00C6 $0223 SUBWF button_button_local_result, W
$00C7 $1D03 BTFSS STATUS, Z
$00C8 $28CE GOTO cistilica_L_7
$00C9 $ cistilica_L_6:
$00C9 $1303 BCF STATUS,RP1
$00CA $1283 BCF STATUS,RP0
$00CB $1306 BCF PORTB, 6
$00CC $3001 MOVLW 1
$00CD $00A0 MOVWF main_global_brojac
$00CE $ cistilica_L_7:
$00CE $ cistilica_L_8:
$00CE $28AD GOTO cistilica_L_0
$00CF $ cistilica_L_5:
$00CF $0008 RETURN
$00D0 $ cistilica_koraktreci:
$00D0 $ cistilica_L_9:
$00D0 $3002 MOVLW 2
$00D1 $1303 BCF STATUS,RP1
$00D2 $1283 BCF STATUS,RP0
$00D3 $0220 SUBWF main_global_brojac, W
$00D4 $1803 BTFSC STATUS, C
$00D5 $28DB GOTO cistilica_L_11
$00D6 $ cistilica_L_10:
$00D6 $30FF MOVLW 255
$00D7 $1303 BCF STATUS,RP1
$00D8 $1283 BCF STATUS,RP0
$00D9 $00F1 MOVWF STACK_1
$00DA $28DE GOTO cistilica_L_12
$00DB $ cistilica_L_11:
$00DB $1303 BCF STATUS,RP1
$00DC $1283 BCF STATUS,RP0
$00DD $01F1 CLRF STACK_1
$00DE $ cistilica_L_12:
$00DE $30FF MOVLW 255
$00DF $1303 BCF STATUS,RP1
$00E0 $1283 BCF STATUS,RP0
$00E1 $0271 SUBWF STACK_1, W
$00E2 $1D03 BTFSS STATUS, Z
$00E3 $28FA GOTO cistilica_L_14
$00E4 $ cistilica_L_13:
$00E4 $3005 MOVLW PORTA
$00E5 $1303 BCF STATUS,RP1
$00E6 $1283 BCF STATUS,RP0
$00E7 $00A4 MOVWF button_button_param_port
$00E8 $3005 MOVLW 5
$00E9 $00A5 MOVWF button_button_param_pin
$00EA $3002 MOVLW 2
$00EB $00A6 MOVWF button_button_param_time
$00EC $01A7 CLRF button_button_param_activestate
$00ED $200D CALL button_button
$00EE $30FF MOVLW 255
$00EF $1303 BCF STATUS,RP1
$00F0 $1283 BCF STATUS,RP0
$00F1 $0223 SUBWF button_button_local_result, W
$00F2 $1D03 BTFSS STATUS, Z
$00F3 $28F9 GOTO cistilica_L_16
$00F4 $ cistilica_L_15:
$00F4 $1303 BCF STATUS,RP1
$00F5 $1283 BCF STATUS,RP0
$00F6 $1686 BSF PORTB, 5
$00F7 $3002 MOVLW 2
$00F8 $00A0 MOVWF main_global_brojac
$00F9 $ cistilica_L_16:
$00F9 $ cistilica_L_17:
$00F9 $28D0 GOTO cistilica_L_9
$00FA $ cistilica_L_14:
$00FA $0008 RETURN
$00FB $ cistilica_korakcetvrti:
$00FB $ cistilica_L_18:
$00FB $3003 MOVLW 3
$00FC $1303 BCF STATUS,RP1
$00FD $1283 BCF STATUS,RP0
$00FE $0220 SUBWF main_global_brojac, W
$00FF $1803 BTFSC STATUS, C
$0100 $2906 GOTO cistilica_L_20
$0101 $ cistilica_L_19:
$0101 $30FF MOVLW 255
$0102 $1303 BCF STATUS,RP1
$0103 $1283 BCF STATUS,RP0
$0104 $00F1 MOVWF STACK_1
$0105 $2909 GOTO cistilica_L_21
$0106 $ cistilica_L_20:
$0106 $1303 BCF STATUS,RP1
$0107 $1283 BCF STATUS,RP0
$0108 $01F1 CLRF STACK_1
$0109 $ cistilica_L_21:
$0109 $30FF MOVLW 255
$010A $1303 BCF STATUS,RP1
$010B $1283 BCF STATUS,RP0
$010C $0271 SUBWF STACK_1, W
$010D $1D03 BTFSS STATUS, Z
$010E $2926 GOTO cistilica_L_23
$010F $ cistilica_L_22:
$010F $3005 MOVLW PORTA
$0110 $1303 BCF STATUS,RP1
$0111 $1283 BCF STATUS,RP0
$0112 $00A4 MOVWF button_button_param_port
$0113 $3004 MOVLW 4
$0114 $00A5 MOVWF button_button_param_pin
$0115 $3002 MOVLW 2
$0116 $00A6 MOVWF button_button_param_time
$0117 $01A7 CLRF button_button_param_activestate
$0118 $200D CALL button_button
$0119 $30FF MOVLW 255
$011A $1303 BCF STATUS,RP1
$011B $1283 BCF STATUS,RP0
$011C $0223 SUBWF button_button_local_result, W
$011D $1D03 BTFSS STATUS, Z
$011E $2925 GOTO cistilica_L_25
$011F $ cistilica_L_24:
$011F $1303 BCF STATUS,RP1
$0120 $1283 BCF STATUS,RP0
$0121 $1606 BSF PORTB, 4
$0122 $1286 BCF PORTB, 5
$0123 $3003 MOVLW 3
$0124 $00A0 MOVWF main_global_brojac
$0125 $ cistilica_L_25:
$0125 $ cistilica_L_26:
$0125 $28FB GOTO cistilica_L_18
$0126 $ cistilica_L_23:
$0126 $0008 RETURN
$0127 $ cistilica_korakpeti:
$0127 $ cistilica_L_27:
$0127 $3004 MOVLW 4
$0128 $1303 BCF STATUS,RP1
$0129 $1283 BCF STATUS,RP0
$012A $0220 SUBWF main_global_brojac, W
$012B $1803 BTFSC STATUS, C
$012C $2932 GOTO cistilica_L_29
$012D $ cistilica_L_28:
$012D $30FF MOVLW 255
$012E $1303 BCF STATUS,RP1
$012F $1283 BCF STATUS,RP0
$0130 $00F1 MOVWF STACK_1
$0131 $2935 GOTO cistilica_L_30
$0132 $ cistilica_L_29:
$0132 $1303 BCF STATUS,RP1
$0133 $1283 BCF STATUS,RP0
$0134 $01F1 CLRF STACK_1
$0135 $ cistilica_L_30:
$0135 $30FF MOVLW 255
$0136 $1303 BCF STATUS,RP1
$0137 $1283 BCF STATUS,RP0
$0138 $0271 SUBWF STACK_1, W
$0139 $1D03 BTFSS STATUS, Z
$013A $2952 GOTO cistilica_L_32
$013B $ cistilica_L_31:
$013B $3005 MOVLW PORTA
$013C $1303 BCF STATUS,RP1
$013D $1283 BCF STATUS,RP0
$013E $00A4 MOVWF button_button_param_port
$013F $3003 MOVLW 3
$0140 $00A5 MOVWF button_button_param_pin
$0141 $3002 MOVLW 2
$0142 $00A6 MOVWF button_button_param_time
$0143 $01A7 CLRF button_button_param_activestate
$0144 $200D CALL button_button
$0145 $30FF MOVLW 255
$0146 $1303 BCF STATUS,RP1
$0147 $1283 BCF STATUS,RP0
$0148 $0223 SUBWF button_button_local_result, W
$0149 $1D03 BTFSS STATUS, Z
$014A $2951 GOTO cistilica_L_34
$014B $ cistilica_L_33:
$014B $1303 BCF STATUS,RP1
$014C $1283 BCF STATUS,RP0
$014D $1206 BCF PORTB, 4
$014E $1386 BCF PORTB, 7
$014F $3004 MOVLW 4
$0150 $00A0 MOVWF main_global_brojac
$0151 $ cistilica_L_34:
$0151 $ cistilica_L_35:
$0151 $2927 GOTO cistilica_L_27
$0152 $ cistilica_L_32:
$0152 $0008 RETURN
$0153 $ cistilica_koraksesti:
$0153 $ cistilica_L_36:
$0153 $3005 MOVLW 5
$0154 $1303 BCF STATUS,RP1
$0155 $1283 BCF STATUS,RP0
$0156 $0220 SUBWF main_global_brojac, W
$0157 $1803 BTFSC STATUS, C
$0158 $295E GOTO cistilica_L_38
$0159 $ cistilica_L_37:
$0159 $30FF MOVLW 255
$015A $1303 BCF STATUS,RP1
$015B $1283 BCF STATUS,RP0
$015C $00F1 MOVWF STACK_1
$015D $2961 GOTO cistilica_L_39
$015E $ cistilica_L_38:
$015E $1303 BCF STATUS,RP1
$015F $1283 BCF STATUS,RP0
$0160 $01F1 CLRF STACK_1
$0161 $ cistilica_L_39:
$0161 $30FF MOVLW 255
$0162 $1303 BCF STATUS,RP1
$0163 $1283 BCF STATUS,RP0
$0164 $0271 SUBWF STACK_1, W
$0165 $1D03 BTFSS STATUS, Z
$0166 $2984 GOTO cistilica_L_41
$0167 $ cistilica_L_40:
$0167 $3000 MOVLW 0
$0168 $1303 BCF STATUS,RP1
$0169 $1283 BCF STATUS,RP0
$016A $1B85 BTFSC PORTA, 7
$016B $3001 MOVLW 1
$016C $00A1 MOVWF main_global_zastavica
$016D $3000 MOVLW 0
$016E $0221 SUBWF main_global_zastavica, W
$016F $1D03 BTFSS STATUS, Z
$0170 $2976 GOTO cistilica_L_43
$0171 $ cistilica_L_42:
$0171 $30FF MOVLW 255
$0172 $1303 BCF STATUS,RP1
$0173 $1283 BCF STATUS,RP0
$0174 $00F3 MOVWF STACK_3
$0175 $2979 GOTO cistilica_L_45
$0176 $ cistilica_L_43:
$0176 $1303 BCF STATUS,RP1
$0177 $1283 BCF STATUS,RP0
$0178 $01F3 CLRF STACK_3
$0179 $ cistilica_L_45:
$0179 $30FF MOVLW 255
$017A $1303 BCF STATUS,RP1
$017B $1283 BCF STATUS,RP0
$017C $0273 SUBWF STACK_3, W
$017D $1D03 BTFSS STATUS, Z
$017E $2983 GOTO cistilica_L_47
$017F $ cistilica_L_46:
$017F $3005 MOVLW 5
$0180 $1303 BCF STATUS,RP1
$0181 $1283 BCF STATUS,RP0
$0182 $00A0 MOVWF main_global_brojac
$0183 $ cistilica_L_47:
$0183 $ cistilica_L_44:
$0183 $2953 GOTO cistilica_L_36
$0184 $ cistilica_L_41:
$0184 $0008 RETURN
$0185 $ cistilica_main:
$0185 $ cistilica_main_main:
$0185 $30FC MOVLW 252
$0186 $1303 BCF STATUS,RP1
$0187 $1683 BSF STATUS,RP0
$0188 $0085 MOVWF TRISA
$0189 $1283 BCF STATUS,RP0
$018A $0185 CLRF PORTA
$018B $1683 BSF STATUS,RP0
$018C $0186 CLRF TRISB
$018D $1283 BCF STATUS,RP0
$018E $0186 CLRF PORTB
$018F $01A2 CLRF main_global_ukljuci
$0190 $01A0 CLRF main_global_brojac
$0191 $3001 MOVLW 1
$0192 $00A1 MOVWF main_global_zastavica
$0193 $ cistilica_L_48:
$0193 $ cistilica_L_49:
$0193 $1303 BCF STATUS,RP1
$0194 $1283 BCF STATUS,RP0
$0195 $3005 MOVLW PORTA
$0196 $1303 BCF STATUS,RP1
$0197 $1283 BCF STATUS,RP0
$0198 $00A4 MOVWF button_button_param_port
$0199 $3007 MOVLW 7
$019A $00A5 MOVWF button_button_param_pin
$019B $3002 MOVLW 2
$019C $00A6 MOVWF button_button_param_time
$019D $01A7 CLRF button_button_param_activestate
$019E $200D CALL button_button
$019F $30FF MOVLW 255
$01A0 $1303 BCF STATUS,RP1
$01A1 $1283 BCF STATUS,RP0
$01A2 $0223 SUBWF button_button_local_result, W
$01A3 $1D03 BTFSS STATUS, Z
$01A4 $29AB GOTO cistilica_L_52
$01A5 $ cistilica_L_51:
$01A5 $206A CALL cistilica_korakprvi
$01A6 $20AD CALL cistilica_korakdrugi
$01A7 $20D0 CALL cistilica_koraktreci
$01A8 $20FB CALL cistilica_korakcetvrti
$01A9 $2127 CALL cistilica_korakpeti
$01AA $2153 CALL cistilica_koraksesti
$01AB $ cistilica_L_52:
$01AB $ cistilica_L_53:
$01AB $2993 GOTO cistilica_L_48
$01AC $ cistilica_L_50:
$01AC $ cistilica_L_54:
$01AC $29AC GOTO cistilica_L_54
zelja
Pocetnik na forumu
Pocetnik na forumu
Posts: 25
Joined: 21-02-2005, 14:05

Post by zelja »

buco wrote:Mislim da ti je sumlja na krivom mijestu . MCU te sigurno ne zeza !!! Provijeri config bitove , iako mi nije jasno kako to mislis radi pa ne radi ?
A mislim da je problem sto mi je ovaj program dolazio do 4 koraka i onda nije izvodio dalje kako treba.
A sad mi taj isti program radi do 4 koraka ali u 4 ne otvara izlaz 4 nego 2!!! i gledam ko budala u kod ali ne kuzim u koju je petlju uletio.

Usput jos koje pitanje:
1. Je li moguce u 16F628 koristiti sve PORTA kao izlazne? jer su mi se cuda dogadjala kad bi koristio RA3, 2, 1 i 0. Releji brzo rade. Zuje???

2. Kako navoditi program? Novi sam u PIC programiranju, ali imam iskustva u programiranju za desktop aplikacije. U ovom programu koristim procedure sa petljama u kojoj se vrti dok ne ispuni uvjet. Koliko je to dobro? Ima li bolja shema? I koliko ih mogu koristiti posto mi se cini da samo prekoracio neka ogranicenja
User avatar
trax
Administrator sajta
Administrator sajta
Posts: 3509
Joined: 08-01-2005, 18:04
Location: 75k, BA
Contact:

Post by trax »

Kod inicijalizacije portova ubaci i ovo:

Code: Select all

CMCON = $07
CCP1CON = $00
Predlazem da naucis asembler i tako pises programe. Jedino tako imas apsolutnu kontrolu nad onome sto se desava u chipu.

Trax
User avatar
[SINNER]
Penjem se :)
Penjem se :)
Posts: 82
Joined: 18-09-2005, 21:44
Location: Bihac-Sarajevo

Post by [SINNER] »

@zelja mislim da si napravio jednu gresku u svom programu a to je da ce ti se ovaj program samo jednom izvrsiti kako treba i nikad vise, posto 'brojac' nikad nisi vratio na nulu! Druga stvar je ta da predjes na assembler posto ce ti program tako mnogo, mnogo manje memorije zauzimati! I izgledao bi nekako ovako:

cblock 0x0C
TEMP1
TEMP2
endc

bsf STATUS, RP0
movlw B'11111100'
movwf TRISA
movlw B'00000000'
movwf TRISB
bcf STATUS, RP0
CLRF PORTA
CLRF PORTB

MAIN CLRWDT ; Ovu naredbu mozes izbrisati ako iskljucis WDT u programatoru!
L1 BTFSS PORTA, 0x07 ; Prskace narednu naredbu ako je PORTA.7=1
GOTO L1
BSF PORTB, 0x07 ; Pali navedeni pin
MOVLW 0xFA
MOVWF TEMP1
CALL PAUZA ; Pauza 250mS
MOVLW 0xFA
MOVWF TEMP1
CALL PAUZA ; Pauza 250mS
BSF PORTB, 0x06 ; Pali navedeni pin
MOVLW 0xFA
MOVWF TEMP1
CALL PAUZA ; Pauza 250mS
MOVLW 0xFA
MOVWF TEMP1
CALL PAUZA ; Pauza 250mS
L2 BTFSS PORTA, 0x06 ; Prskace narednu naredbu ako je PORTA.6=1
GOTO L2
BCF PORTB, 0x06 ; Gasi navedeni pin
L3 BTFSS PORTA, 0x05 ; Prskace narednu naredbu ako je PORTA.5=1
GOTO L3
BSF PORTB, 0x05 ; Pali navedeni pin
L4 BTFSS PORTA, 0x04 ; Prskace narednu naredbu ako je PORTA.4=1
GOTO L4
BSF PORTB, 0x04 ; Pali navedeni pin
BCF PORTB, 0x05 ; Gasi navedeni pin
L5 BTFSS PORTA, 0x03 ; Prskace narednu naredbu ako je PORTA.3=1
GOTO L5
BCF PORTB, 0x04 ; Gasi navedeni pin
BCF PORTB, 0x07 ; Gasi navedeni pin
;*************************************************
OVAJ KORAK TI BAS NE KONTAM STA CE TI I STA RADI
PA GA NISAM NAPISAO!
sub procedure korakSesti

While brojac<5

zastavica = TestBit(PORTA, 7)

If zastavica=0 Then ' profil je izvucen, vracaj se u glavnu petlju i zavrsi
brojac=5
End If
Wend

end sub
;*************************************************
GOTO MAIN

PAUZA MOVLW 0x63
MOVWF TEMP2
PAUZAX NOP
NOP
NOP
NOP
NOP
NOP
NOP
DECFSZ TEMP2, F
GOTO PAUZAX
DECFSZ TEMP1, F
GOTO PAUZA
RETURN
END

Ej ja ti nisam koristio taj PIC16F628, koristim inace PIC16F84A pa ova funkcija PAUZA je namjenjena za njega i kritsl od 4MHz. Ako sam napravio kakvu grsku slobodno ispravite :roll:

POZDRAV

http://www.elektronika.ba/forum/uploadz ... 3_Prog.txt
User avatar
[SINNER]
Penjem se :)
Penjem se :)
Posts: 82
Joined: 18-09-2005, 21:44
Location: Bihac-Sarajevo

Post by [SINNER] »

Ej sad sam malo gledao data sheet od PIC16F628 i moj ti je savjet da preskocis PORTA.5 pin mjesto njega uzmi neki drugi pin npr. PORTA.2 :) PORTA.5 ti je MCLR pin, a on se koristi za reset samog PIC-a, on bi ti stalno trebao biti na +5V preko otpornika od nekih 1K-10K.

POZDRAV i SRETNO
buco

Post by buco »

RA5 bi naravno mogao koristiti jer se chip ionako resetira postavljanjem POR bitu [ power on reset ] ili je to automatski [ kod vecine processora ]. Nije potrebno drzat pullup otpornik ukopcan [ ne treba mu vanjski kad ionako mozes setirat interni 10K] .
Ali ako to @zelji pravi problem nek ga mijenja ! tj redefinira portove.
Ja zaista nisam stigao nist jos pogledat [ iako mu i najgori disassembler nebi onako izlistao kod , vidi se koji alat je u igri ] .
@sinner ti si dobro uputio covijeka sad treba vidjet korak 5 i 6 jel tako ?
zasto ne rade .
@zelja Poslusaj savijete traxa prouci assembler za PIC [ naredbe] skini
s microchipove stranice najnoviji MPLAB i vidjet ces koliko je bolje i jednostavnije , kolikogod da to to zvuci cudno radit u assembleru . Ipak su to mali 8 bitni strojevi s relativno malom prg memorijom , pa ce ti kod biti bolje "uskladjen" , jednostavniji i imat ces full kontrolu nad sustavom za kojeg pises program ..itd.
User avatar
[SINNER]
Penjem se :)
Penjem se :)
Posts: 82
Joined: 18-09-2005, 21:44
Location: Bihac-Sarajevo

Post by [SINNER] »

Ej ima jos jedno rjesenje tvog problema a to je kad programiras PIC iskljuci MCLR u ICProg-u!
I mislim da obavezno moras staviti ono sto je @Trax rekao:

Code: Select all

CMCON = $07 
CCP1CON = $00
POZDRAV :)

http://www.elektronika.ba/forum/uploadz ... um.bmp.txt
buco

Post by buco »

@Zelja mozes to postavit , izvrsni kod , u hex porfmatu na board , pa cu ga ja diassemblirat jer ovo je nesto cudno , program te vodi kao prvo po nepostojecim rutinama [ fiktivno su samo navedene ] neobicnu su definirani neke operacije isl !!
Inace ti je dobro kad uzmes neki MCU za radit s njim da se upoznas s njegovom strukturom unitrasnjom , konfiguracionim registrima , registrima postavki , prekidim vektorom , tipovima oscilatora , sekundarnim funkcijama portova isl tj sa HW i SW inicijalnim registrima gdije konfiguriras pocetne ili tranije uvijete u HW samog MCUa . To ti je najlakse ako skines dokument s neta o MCUu s kojim radis . Jer kod programiranja kontrolera [ mikroracunala] nemas "taticu" koji je kroz bios odradio "magareci" posao definicje rada portova , broja portova , tipova jedinica u sustavu , pa kroz kernel jos ti sve to skupa nadogradio i ti o tome nema da brines i zapravo i vecina ih o tome i pojima nema [ mislim na mehanizam kako to zapravo radi , rutine biosa i kernela]. E tu kod tih malih masina i upotrebom publik alata [ HPLi + crosscompileri] pa i ovih "polu pro" morat ces ipak upoznat svoje malo racunalo na onoj najnizoj razini tj samo arhitekturi internoj. Da bi tvoji uradci , programi, bili operativni i efikasni !!!!! To je jedna od najvecih razlika izrade programa za PC ili za na mikrocontroller !! Bar onoliko koliko ja poznam programiranje za PC u HPLima !
zelja
Pocetnik na forumu
Pocetnik na forumu
Posts: 25
Joined: 21-02-2005, 14:05

Post by zelja »

e svaka vam cast. stvarno ste se potrudili analizirati moje brljotine.

I da. Svjestan sam da za bilo sta ozbiljno moram uciti asembler.Ali dobio zadatak koji sam mislio rijesiti uz malo muke. Ali kako to obicno biva u zivotu stvar se zakomplicira.

@sinner - korak sesti mi je bio za cekanje dok na ulazu 1 ne bude 0. Odnosno dok korisnik ne izvuce profil iz stroja. Onda se vraca na pocetnu petlju i ceka kad ce ponovo na ulazu 1 biti 1

@buco - skinuo sam MPlab i prije, i poceo uciti, ali me onda rokovi pritiskli i morao sam ovo sto prije zavrsiti da bi proslo, na kraju nisam zavrsio na vrijeme i propao mi je posao. Ali bit ce bolje drugi put.

Truditi cu se zavrsiti ovaj projekt kako bi malo bolje naucio programiranje za PIC. Iako mi je sada trenutno jako tesko pojmiti kako kontrolirati tijek izvodjenja i blokirati PIC sve dok ne budu ispunjeni uvjeti koje trazim.

Je li ovaj nacin sto sam prije imao dobar (petlja while) ili na pic-u se to radi na drugaciji nacin.
buco

Post by buco »

Da izgleda je bilo bolje da si bar nesto proucio arhitekturu PIC 16 serije [ i samog konkretnog MCUa] i assembler.
Do while / while end petlje , petlja ko petlja ako je dobro postavljena trebala bi radit , nema razloga da ne , medjutim osnovni "konflikt" corsscompilera i rada u assembleru je taj sto nikad neznas kako ce u odredjenim uvijetima [ kombinacijama naredbi HPLa] compiler reagirat tj kakv izvrsni kod ce zapravo ispast !! Kad sam malo pogledas svoj izvrsni kod vec vidis kako je na tako malom programu generirao par virtualnih rutina [ ne sluze nicemu] a i neke naredbe postavio koje u kombinaciji s ostalima koje slijede uopce ne trbaju .
Kontrola tijeka izvodjenja programa ! Radom u assembleru ti si master i ono sto ti kazes [ napises] to je "amen" za MCU , ti tocno znas sto ce bit generirano dok kod crosscompilera nema toga koji ce se zaklet sto cemu tocno bit generirano u izvrsni kod . Broj naredbi MPASMa u praksi je relativno mali koji se koristi u vecoj kolicini , neposredni unos, posredni FSR[indexni registar] , prijenos na accumulator , iscitavnje istog , grananje uvijetno i bezuvijetno , ostalo ti je uglavnom po potrebi [ naredbe za rad sa specijalnim funkcijama MCUa isl. ] !!
Uvijetnom petljom se najcesce "blokira" processor tj stavlja u neku vrst cekanja ako to tako zahtijeva tok programa [ da nemoze dalje ako ne zadovolji odredjeni uvijet ] . Zanimljivost kod mikrochipovih kontrolera serija 16 je zadrzan nazasot stari nacin arhitekture , "accumulatorski orijentiranog sustava " sto bas nije jako moderno i trosi vrijeme a i resurse [ prg memoriju] , dobra starana je sto taj model nema ogranicenje upotrebe broja registara [ samo fiziko , koliko je sram ] .
Nabavi si jedan mali diassembler za pic seriju dobro dodje !!!!
Pa postavi taj hex code da ga disasembliram ! Bit ce mi lakse nego pratit
nego ono sto je tamo postavljeno.
User avatar
[SINNER]
Penjem se :)
Penjem se :)
Posts: 82
Joined: 18-09-2005, 21:44
Location: Bihac-Sarajevo

Post by [SINNER] »

@sinner - korak sesti mi je bio za cekanje dok na ulazu 1 ne bude 0. Odnosno dok korisnik ne izvuce profil iz stroja. Onda se vraca na pocetnu petlju i ceka kad ce ponovo na ulazu 1 biti 1
OK taj sam dio i kontao :) , ali problem je sto si u koraku sest stavio brojac=5. I tim si se vratio u glavnu petlju, zatim opet krenes iz pocetka i provjeris da li je PODTA.7= 1 prodje i prvi korak i to je OK. :) Ali u drugom koraku ti stoji While brojac<1 a tebi je zadnja vrijednost brojaca bila 5, TU JE PROBLEM :!: Zar ne bi trebao brojac biti ili 0 ili 1 da se izvrsi i ovaj korak :?:

P.S. U ovom gore assemblerskom kodu sto sam ti napisao mjesto koraka sest samo bi trebao staviti:

L6 BTFSC PORTA, 0x07 ; Prskace narednu naredbu ako je PORTA.7=0
GOTO L6
zelja
Pocetnik na forumu
Pocetnik na forumu
Posts: 25
Joined: 21-02-2005, 14:05

Post by zelja »

[SINNER] wrote:
OK taj sam dio i kontao :) , ali problem je sto si u koraku sest stavio brojac=5. I tim si se vratio u glavnu petlju, zatim opet krenes iz pocetka i provjeris da li je PODTA.7= 1 prodje i prvi korak i to je OK. :) Ali u drugom koraku ti stoji While brojac<1 a tebi je zadnja vrijednost brojaca bila 5, TU JE PROBLEM :!: Zar ne bi trebao brojac biti ili 0 ili 1 da se izvrsi i ovaj korak :?:
Je je. U pravu si. Sad to vidjeh. Trebao bi u zadnjem koraku i brojac postaviti na 0. Ali nisam stigao to ni debagirati posto sam zapeo prije tog koraka.

Ali hvala. Od velike si pomoci.
User avatar
[SINNER]
Penjem se :)
Penjem se :)
Posts: 82
Joined: 18-09-2005, 21:44
Location: Bihac-Sarajevo

Post by [SINNER] »

OK i drugi put :)
Post Reply