A discussion group for the PICMicro microcontroller. Also called the Microchip PIC, this list is dedicated to the use and abuse of this fine, simple, microcontroller. Close to topic posts are welcome, ie. general electronics.
|
Hi Guys,
I have been stuck on this problem for 3 days so I hope i can get some input from this group. Issue: To send 2 bytes eg. say 0x03B via RB7 pin. KNOWN: I can test for (1) or (0) on RB7 pin for start-up. Setting trisb & portb are no problem. saving w reg to File registers are no problem. Problem: What sort of code will i basically need, to send 3Bh via rb7 ? What is this method call ? I can provide snippets of my code if required. thanks in advance, tony |
|
|
|
Since you are trying to send the data in a serial manner the easiest thing would be to: 1) load first byte to a temp location 2) call subroutine 3) load second byte to a temp location 4) call subroutine subroutine: 1) set a loop counter to 8 (bits to process) 2) load byte from temp location to W 3) shift left into carry (RLF) 4) store W back in temp location 5) if Carry is set, set PORTB.7 else clear PORTB.7 6) decrement loop counter 7) if loop counter > 0 goto 2 8) return The problem with such a scheme is clocking. How does the receiver of this bit stream know that 2 adjacent 0's (or 1's) are two distinct bits and not just one long bit? --- In , "fivpenguin3000" <fivpenguin3000@y...> wrote: > Hi Guys, > I have been stuck on this problem for 3 days so I hope i can get > some input from this group. > > Issue: > To send 2 bytes eg. say 0x03B via RB7 pin. > > KNOWN: I can test for (1) or (0) on RB7 pin for start-up. > Setting trisb & portb are no problem. > saving w reg to File registers are no problem. > > Problem: What sort of code will i basically need, to send 3Bh via > rb7 ? What is this method call ? > I can provide snippets of my code if required. > thanks in advance, > tony |
|
|
|
Just so happens, I was cleaning up a macro for posting to do just that, not posted yet, but have it attached. It has constant bit rate, so simulates asynchonous, but stop bit is not implemented. Chad --- rtstofer <> wrote: > Since you are trying to send the data in a serial manner the easiest > thing would be to: > > 1) load first byte to a temp location > 2) call subroutine > 3) load second byte to a temp location > 4) call subroutine > > subroutine: > 1) set a loop counter to 8 (bits to process) > 2) load byte from temp location to W > 3) shift left into carry (RLF) > 4) store W back in temp location > 5) if Carry is set, set PORTB.7 else clear PORTB.7 > 6) decrement loop counter > 7) if loop counter > 0 goto 2 > 8) return > > The problem with such a scheme is clocking. How does the receiver > of this bit stream know that 2 adjacent 0's (or 1's) are two > distinct bits and not just one long bit? > > --- In , "fivpenguin3000" > <fivpenguin3000@y...> wrote: > > Hi Guys, > > > > > > I have been stuck on this problem for 3 days so I hope i can get > > some input from this group. > > > > Issue: > > To send 2 bytes eg. say 0x03B via RB7 pin. > > > > KNOWN: I can test for (1) or (0) on RB7 pin for start-up. > > Setting trisb & portb are no problem. > > saving w reg to File registers are no problem. > > > > Problem: What sort of code will i basically need, to send 3Bh via > > rb7 ? What is this method call ? > > > > > > I can provide snippets of my code if required. > > > > > > thanks in advance, > > > > > > tony __________________________________ | |||
|
|
Thankyou very much for your valued response rtstofer! It's helped me out a lot! I have gone through the pointers & all makes sense. Just one little hick-up, & i will search through the piclist FAQ but just on point 5. Its sort of a catch 22 situation for me.... If i test for the Carry bit using BTFSS or BTFSC i.e. BTFSS STATUS, C If set, then i must BSF PORTB, RB7 which is ok. But if its clear then i am stuck clearing & setting. Even if i try BTFSC, i get myself in the same predicament! so... btfss status, c bcf portb, rb7 bsf portb, rb7 So essentially, the answer here is, how do i do IF/ELSE statements in PIC assembly ? BTW:) OK. You brought up some important questions. Firstly, i need to find out the start/stop bits. As far as clocking goes, RB6 is the clock signal. This setup is a goldwafer card. RB7 is data, RB6 is clock. But i am a beginner in PIC micro's but i love it to say the least. I wonder if its possible to time the clock signals using RB6 as input versus a time axis. I don't know what timers PIC's have which may be able to measure then calculate the clock speed in MHz. Oh, maybe i can set a loop which reads input 100 times but i need some timer in the background...... cheers tony ----- Original Message ----- From: "rtstofer" <> To: <> Sent: Monday, November 17, 2003 11:05 AM Subject: [piclist] Re: Stream ouput on RB7 pin using 16f84.. > Since you are trying to send the data in a serial manner the easiest > thing would be to: > > 1) load first byte to a temp location > 2) call subroutine > 3) load second byte to a temp location > 4) call subroutine > > subroutine: > 1) set a loop counter to 8 (bits to process) > 2) load byte from temp location to W > 3) shift left into carry (RLF) > 4) store W back in temp location > 5) if Carry is set, set PORTB.7 else clear PORTB.7 > 6) decrement loop counter > 7) if loop counter > 0 goto 2 > 8) return > > The problem with such a scheme is clocking. How does the receiver > of this bit stream know that 2 adjacent 0's (or 1's) are two > distinct bits and not just one long bit? > > --- In , "fivpenguin3000" > <fivpenguin3000@y...> wrote: > > Hi Guys, > > > > > > I have been stuck on this problem for 3 days so I hope i can get > > some input from this group. > > > > Issue: > > To send 2 bytes eg. say 0x03B via RB7 pin. > > > > KNOWN: I can test for (1) or (0) on RB7 pin for start-up. > > Setting trisb & portb are no problem. > > saving w reg to File registers are no problem. > > > > Problem: What sort of code will i basically need, to send 3Bh via > > rb7 ? What is this method call ? > > > > > > I can provide snippets of my code if required. > > > > > > thanks in advance, > > > > > > tony > > to unsubscribe, go to http://www.yahoogroups.com and follow the instructions |
|
|
|
Because the PIC doesn't have conditional jump instructions, IF-THEN- ELSE looks a little ugly: BTFSC STATUS,C ; skip the next GOTO if C is clear GOTO CARRY_SET BCF PORTB,7 ; carry was clear so clear the output bit GOTO ALL_DONE CARRY_SET: BSF PORTB,7 ; carry was set so set the output bit ALL_DONE: .... ; the rest of the code Asynchronous communication occurs without a specific clock because both the receiver and transmitter agree to a baud rate. The start bit allows the receiver to synchronize with the transmitter and the stop bit validates the transmission of one byte. Synchronous communication occurs with a clock signal sent along with the data signal. Like RB6 in your case. This is the easiest to implement: set the data bit and toggle the clock. Start and stop bits can be added to the data stream to simplify synchronizing the receiver. Various PICS have both an asynchronous and synchronous transceiver - are you sure you can't use them? --- In , "Tony PETROSKI" <fivpenguin3000@y...> wrote: > Thankyou very much for your valued response rtstofer! > > It's helped me out a lot! I have gone through the pointers & all makes > sense. > > Just one little hick-up, & i will search through the piclist FAQ but just on > point 5. Its sort of a catch 22 situation for me.... > > If i test for the Carry bit using BTFSS or BTFSC i.e. BTFSS STATUS, C > > If set, then i must BSF PORTB, RB7 which is ok. But if its clear then i am > stuck clearing & setting. > Even if i try BTFSC, i get myself in the same predicament! > > so... > > btfss status, c > bcf portb, rb7 > bsf portb, rb7 > So essentially, the answer here is, how do i do IF/ELSE statements in PIC > assembly ? > BTW:) OK. You brought up some important questions. Firstly, i need to find > out the start/stop bits. As far as clocking goes, RB6 is the clock signal. > This setup is a goldwafer card. RB7 is data, RB6 is clock. But i am a > beginner in PIC micro's but i love it to say the least. I wonder if its > possible to time the clock signals using RB6 as input versus a time axis. I > don't know what timers PIC's have which may be able to measure then > calculate the clock speed in MHz. Oh, maybe i can set a loop which reads > input 100 times but i need some timer in the background...... > > > cheers > tony > > > ----- Original Message ----- > From: "rtstofer" <rstofer@p...> > To: <> > Sent: Monday, November 17, 2003 11:05 AM > Subject: [piclist] Re: Stream ouput on RB7 pin using 16f84.. > > Since you are trying to send the data in a serial manner the easiest > > thing would be to: > > > > 1) load first byte to a temp location > > 2) call subroutine > > 3) load second byte to a temp location > > 4) call subroutine > > > > subroutine: > > 1) set a loop counter to 8 (bits to process) > > 2) load byte from temp location to W > > 3) shift left into carry (RLF) > > 4) store W back in temp location > > 5) if Carry is set, set PORTB.7 else clear PORTB.7 > > 6) decrement loop counter > > 7) if loop counter > 0 goto 2 > > 8) return > > > > The problem with such a scheme is clocking. How does the receiver > > of this bit stream know that 2 adjacent 0's (or 1's) are two > > distinct bits and not just one long bit? > > > > --- In , "fivpenguin3000" > > <fivpenguin3000@y...> wrote: > > > Hi Guys, > > > > > > > > > I have been stuck on this problem for 3 days so I hope i can get > > > some input from this group. > > > > > > Issue: > > > To send 2 bytes eg. say 0x03B via RB7 pin. > > > > > > KNOWN: I can test for (1) or (0) on RB7 pin for start-up. > > > Setting trisb & portb are no problem. > > > saving w reg to File registers are no problem. > > > > > > Problem: What sort of code will i basically need, to send 3Bh via > > > rb7 ? What is this method call ? > > > > > > > > > I can provide snippets of my code if required. > > > > > > > > > thanks in advance, > > > > > > > > > tony > > > > > > > > to unsubscribe, go to http://www.yahoogroups.com and follow the > instructions > > > > > > > |
|
Oh, thanks again rtstofer!!! I worked that out late last night.......Unfortunanetly, i have this really annoying BUG! I spent hours last night trying to work it out! It's sent me crazy...i don't know if there is a solution. I will post my current code. In the code, i have written a comment ; remove this line. Now if make any arbitary changes like add extra variables in CBLOCK or remove these lines the RLF shift operation doesn't work right. The following table shows how i think the RLF should work after 8 increments.. status 00011000 3B 00111011 0status 00011000 76 01110110 1status 00011000 EC 11101100 2status 00011001 D8 11011000 3status 00011001 B1 10110001 4status 00011001 63 01100011 5status 00011000 C7 11000111 6status 00011001 8E 10001110 7status 00011001 1D 00011101 0011 1011 3 B Yet, you run this code with those ; REMOVE THIS LINE , it won't work! I don't know why the RLF shift is NOT CONSISTANT. Please this has really stumped me.. title "FirstAp.asm" ; Tony PETROSKI ; Nov, 2003 LIST R=DEC INCLUDE "p16f84a.inc" ; Register usage CBLOCK 0x020 ; start registers at end of values k, tempV ENDC START org 0000h ; clear file registers clrw clrf PORTB clrf k clrf tempV ; set tris & ports movlw 0x000 bsf STATUS, RP0 ; bank 1 movwf TRISB ^ 0x080 bcf STATUS, RP0 ; bank0 clrf PORTB ; initialise variables i, j, k movlw 0x008 movwf k ; w = 5 ; mainRoutine mainR movlw 0x03B movwf tempV call sendBt movlw 0x029 ; REMOVE THIS LINE movwf tempV ; REMOVE THIS LINE call sendBt ; REMOVE THIS LINE movlw 0x000 ; REMOVE THIS LINE movwf tempV ; REMOVE THIS LINE call sendBt ; REMOVE THIS LINE ; How can i come back to this mainroutine properly ? goto $ ; loop forever sendBt rlf tempV, w ; left shift tempV movwf tempV btfsc STATUS, C goto bitSet bcf PORTB, 7 goto deCremt bitSet bsf PORTB, IRP deCremt decfsz k, f ; decrement k until = 0 goto sendBt end ----- Original Message ----- From: "rtstofer" <> To: <> Sent: Tuesday, November 18, 2003 12:35 AM Subject: [piclist] Re: Stream ouput on RB7 pin using 16f84.. > > Because the PIC doesn't have conditional jump instructions, IF-THEN- > ELSE looks a little ugly: > > BTFSC STATUS,C ; skip the next GOTO if C is clear > GOTO CARRY_SET > > BCF PORTB,7 ; carry was clear so clear the output bit > GOTO ALL_DONE > > CARRY_SET: > BSF PORTB,7 ; carry was set so set the output bit > > ALL_DONE: > .... ; the rest of the code > Asynchronous communication occurs without a specific clock because > both the receiver and transmitter agree to a baud rate. The start > bit allows the receiver to synchronize with the transmitter and the > stop bit validates the transmission of one byte. > > Synchronous communication occurs with a clock signal sent along with > the data signal. Like RB6 in your case. This is the easiest to > implement: set the data bit and toggle the clock. Start and stop > bits can be added to the data stream to simplify synchronizing the > receiver. > > Various PICS have both an asynchronous and synchronous transceiver - > are you sure you can't use them? > > --- In , "Tony PETROSKI" > <fivpenguin3000@y...> wrote: > > Thankyou very much for your valued response rtstofer! > > > > It's helped me out a lot! I have gone through the pointers & all > makes > > sense. > > > > Just one little hick-up, & i will search through the piclist FAQ > but just on > > point 5. Its sort of a catch 22 situation for me.... > > > > If i test for the Carry bit using BTFSS or BTFSC i.e. BTFSS > STATUS, C > > > > If set, then i must BSF PORTB, RB7 which is ok. But if its clear > then i am > > stuck clearing & setting. > > Even if i try BTFSC, i get myself in the same predicament! > > > > so... > > > > btfss status, c > > bcf portb, rb7 > > bsf portb, rb7 > > > > > > So essentially, the answer here is, how do i do IF/ELSE statements > in PIC > > assembly ? > > > > > > BTW:) OK. You brought up some important questions. Firstly, i need > to find > > out the start/stop bits. As far as clocking goes, RB6 is the clock > signal. > > This setup is a goldwafer card. RB7 is data, RB6 is clock. But i > am a > > beginner in PIC micro's but i love it to say the least. I wonder > if its > > possible to time the clock signals using RB6 as input versus a > time axis. I > > don't know what timers PIC's have which may be able to measure then > > calculate the clock speed in MHz. Oh, maybe i can set a loop which > reads > > input 100 times but i need some timer in the background...... > > > > > > > > > > cheers > > > > > > tony > > > > > > > > > > ----- Original Message ----- > > From: "rtstofer" <rstofer@p...> > > To: <> > > Sent: Monday, November 17, 2003 11:05 AM > > Subject: [piclist] Re: Stream ouput on RB7 pin using 16f84.. > > > > > > > Since you are trying to send the data in a serial manner the > easiest > > > thing would be to: > > > > > > 1) load first byte to a temp location > > > 2) call subroutine > > > 3) load second byte to a temp location > > > 4) call subroutine > > > > > > subroutine: > > > 1) set a loop counter to 8 (bits to process) > > > 2) load byte from temp location to W > > > 3) shift left into carry (RLF) > > > 4) store W back in temp location > > > 5) if Carry is set, set PORTB.7 else clear PORTB.7 > > > 6) decrement loop counter > > > 7) if loop counter > 0 goto 2 > > > 8) return > > > > > > The problem with such a scheme is clocking. How does the > receiver > > > of this bit stream know that 2 adjacent 0's (or 1's) are two > > > distinct bits and not just one long bit? > > > > > > --- In , "fivpenguin3000" > > > <fivpenguin3000@y...> wrote: > > > > Hi Guys, > > > > > > > > > > > > I have been stuck on this problem for 3 days so I hope i can > get > > > > some input from this group. > > > > > > > > Issue: > > > > To send 2 bytes eg. say 0x03B via RB7 pin. > > > > > > > > KNOWN: I can test for (1) or (0) on RB7 pin for start-up. > > > > Setting trisb & portb are no problem. > > > > saving w reg to File registers are no problem. > > > > > > > > Problem: What sort of code will i basically need, to send 3Bh > via > > > > rb7 ? What is this method call ? > > > > > > > > > > > > I can provide snippets of my code if required. > > > > > > > > > > > > thanks in advance, > > > > > > > > > > > > tony > > > > > > > > > > > > to unsubscribe, go to http://www.yahoogroups.com and follow the > > instructions > > > > > > > > > > > > > to unsubscribe, go to http://www.yahoogroups.com and follow the instructions |
|
|
|
You have to initialize the variable 'k' within the sendBt subroutine before you start dealing with the RLF stuff. --- In , "Tony PETROSKI" <fivpenguin3000@y...> wrote: > Oh, thanks again rtstofer!!! I worked that out late last > night.......Unfortunanetly, i have this really annoying BUG! I spent hours > last night trying to work it out! It's sent me crazy...i don't know if there > is a solution. I will post my current code. In the code, i have written a > comment ; remove this line. Now if make any arbitary changes like add extra > variables in CBLOCK or remove these lines the RLF shift operation doesn't > work right. The following table shows how i think the RLF should work after > 8 increments.. > > status 00011000 3B 00111011 > > 0status 00011000 76 01110110 > 1status 00011000 EC 11101100 > 2status 00011001 D8 11011000 > 3status 00011001 B1 10110001 > 4status 00011001 63 01100011 > 5status 00011000 C7 11000111 > 6status 00011001 8E 10001110 > 7status 00011001 1D 00011101 > > 0011 1011 > 3 B > > Yet, you run this code with those ; REMOVE THIS LINE , it won't work! I > don't know why the RLF shift is NOT CONSISTANT. Please this has really > stumped me.. > > title "FirstAp.asm" > > ; Tony PETROSKI > ; Nov, 2003 > > LIST R=DEC > INCLUDE "p16f84a.inc" > > ; Register usage > > CBLOCK 0x020 ; start registers at end of values > k, tempV > ENDC > START org 0000h > > ; clear file registers > clrw > clrf PORTB > clrf k > clrf tempV > > ; set tris & ports > movlw 0x000 > bsf STATUS, RP0 ; bank 1 > movwf TRISB ^ 0x080 > bcf STATUS, RP0 ; bank0 > clrf PORTB > > ; initialise variables i, j, k > movlw 0x008 > movwf k ; w = 5 > > ; mainRoutine > mainR movlw 0x03B > movwf tempV > call sendBt > > movlw 0x029 ; REMOVE THIS LINE > movwf tempV ; REMOVE THIS LINE > call sendBt ; REMOVE THIS LINE > > movlw 0x000 ; REMOVE THIS LINE > movwf tempV ; REMOVE THIS LINE > call sendBt ; REMOVE THIS LINE > ; How can i come back to this mainroutine properly ? > goto $ ; loop forever > sendBt rlf tempV, w ; left shift tempV > > movwf tempV > > btfsc STATUS, C > goto bitSet > bcf PORTB, 7 > goto deCremt > bitSet bsf PORTB, IRP > > deCremt decfsz k, f ; decrement k until = 0 > goto sendBt > end > ----- Original Message ----- > From: "rtstofer" <rstofer@p...> > To: <> > Sent: Tuesday, November 18, 2003 12:35 AM > Subject: [piclist] Re: Stream ouput on RB7 pin using 16f84.. > > > > Because the PIC doesn't have conditional jump instructions, IF- THEN- > > ELSE looks a little ugly: > > > > BTFSC STATUS,C ; skip the next GOTO if C is clear > > GOTO CARRY_SET > > > > BCF PORTB,7 ; carry was clear so clear the output bit > > GOTO ALL_DONE > > > > CARRY_SET: > > BSF PORTB,7 ; carry was set so set the output bit > > > > ALL_DONE: > > .... ; the rest of the code > > > > > > Asynchronous communication occurs without a specific clock because > > both the receiver and transmitter agree to a baud rate. The start > > bit allows the receiver to synchronize with the transmitter and the > > stop bit validates the transmission of one byte. > > > > Synchronous communication occurs with a clock signal sent along with > > the data signal. Like RB6 in your case. This is the easiest to > > implement: set the data bit and toggle the clock. Start and stop > > bits can be added to the data stream to simplify synchronizing the > > receiver. > > > > Various PICS have both an asynchronous and synchronous transceiver - > > are you sure you can't use them? > > > > --- In , "Tony PETROSKI" > > <fivpenguin3000@y...> wrote: > > > Thankyou very much for your valued response rtstofer! > > > > > > It's helped me out a lot! I have gone through the pointers & all > > makes > > > sense. > > > > > > Just one little hick-up, & i will search through the piclist FAQ > > but just on > > > point 5. Its sort of a catch 22 situation for me.... > > > > > > If i test for the Carry bit using BTFSS or BTFSC i.e. BTFSS > > STATUS, C > > > > > > If set, then i must BSF PORTB, RB7 which is ok. But if its clear > > then i am > > > stuck clearing & setting. > > > Even if i try BTFSC, i get myself in the same predicament! > > > > > > so... > > > > > > btfss status, c > > > bcf portb, rb7 > > > bsf portb, rb7 > > > > > > > > > So essentially, the answer here is, how do i do IF/ELSE statements > > in PIC > > > assembly ? > > > > > > > > > BTW:) OK. You brought up some important questions. Firstly, i need > > to find > > > out the start/stop bits. As far as clocking goes, RB6 is the clock > > signal. > > > This setup is a goldwafer card. RB7 is data, RB6 is clock. But i > > am a > > > beginner in PIC micro's but i love it to say the least. I wonder > > if its > > > possible to time the clock signals using RB6 as input versus a > > time axis. I > > > don't know what timers PIC's have which may be able to measure then > > > calculate the clock speed in MHz. Oh, maybe i can set a loop which > > reads > > > input 100 times but i need some timer in the background...... > > > > > > > > > > > > > > > cheers > > > > > > > > > tony > > > > > > > > > > > > > > > ----- Original Message ----- > > > From: "rtstofer" <rstofer@p...> > > > To: <> > > > Sent: Monday, November 17, 2003 11:05 AM > > > Subject: [piclist] Re: Stream ouput on RB7 pin using 16f84.. > > > > > > > > > > Since you are trying to send the data in a serial manner the > > easiest > > > > thing would be to: > > > > > > > > 1) load first byte to a temp location > > > > 2) call subroutine > > > > 3) load second byte to a temp location > > > > 4) call subroutine > > > > > > > > subroutine: > > > > 1) set a loop counter to 8 (bits to process) > > > > 2) load byte from temp location to W > > > > 3) shift left into carry (RLF) > > > > 4) store W back in temp location > > > > 5) if Carry is set, set PORTB.7 else clear PORTB.7 > > > > 6) decrement loop counter > > > > 7) if loop counter > 0 goto 2 > > > > 8) return > > > > > > > > The problem with such a scheme is clocking. How does the > > receiver > > > > of this bit stream know that 2 adjacent 0's (or 1's) are two > > > > distinct bits and not just one long bit? > > > > > > > > --- In , "fivpenguin3000" > > > > <fivpenguin3000@y...> wrote: > > > > > Hi Guys, > > > > > > > > > > > > > > > I have been stuck on this problem for 3 days so I hope i can > > get > > > > > some input from this group. > > > > > > > > > > Issue: > > > > > To send 2 bytes eg. say 0x03B via RB7 pin. > > > > > > > > > > KNOWN: I can test for (1) or (0) on RB7 pin for start-up. > > > > > Setting trisb & portb are no problem. > > > > > saving w reg to File registers are no problem. > > > > > > > > > > Problem: What sort of code will i basically need, to send 3Bh > > via > > > > > rb7 ? What is this method call ? > > > > > > > > > > > > > > > I can provide snippets of my code if required. > > > > > > > > > > > > > > > thanks in advance, > > > > > > > > > > > > > > > tony > > > > > > > > > > > > > > > > to unsubscribe, go to http://www.yahoogroups.com and follow the > > > instructions > > > > > > > > > > > > > > > > > > > > > > > > to unsubscribe, go to http://www.yahoogroups.com and follow the > instructions > > > > > > > |
|
Ok. But i just tried putting.. > ; initialise variables k > movlw 0x008 > movwf k ; w = 8 into sendBt routine and it still doesn't do RLF properly! So this is what i did.... sendBt movlw 0x008 movwf k ; w = 8 rlf tempV, w ; left shift tempV movwf tempV And by doing this, my counter will not work as the variable 'k' will start with number 8 on every loop! ----- Original Message ----- From: "rtstofer" <> To: <> Sent: Tuesday, November 18, 2003 1:03 PM Subject: [piclist] Re: Stream ouput on RB7 pin using 16f84.. > > You have to initialize the variable 'k' within the sendBt subroutine > before you start dealing with the RLF stuff. > --- In , "Tony PETROSKI" > <fivpenguin3000@y...> wrote: > > Oh, thanks again rtstofer!!! I worked that out late last > > night.......Unfortunanetly, i have this really annoying BUG! I > spent hours > > last night trying to work it out! It's sent me crazy...i don't > know if there > > is a solution. I will post my current code. In the code, i have > written a > > comment ; remove this line. Now if make any arbitary changes like > add extra > > variables in CBLOCK or remove these lines the RLF shift operation > doesn't > > work right. The following table shows how i think the RLF should > work after > > 8 increments.. > > > > status 00011000 3B 00111011 > > > > 0status 00011000 76 01110110 > > 1status 00011000 EC 11101100 > > 2status 00011001 D8 11011000 > > 3status 00011001 B1 10110001 > > 4status 00011001 63 01100011 > > 5status 00011000 C7 11000111 > > 6status 00011001 8E 10001110 > > 7status 00011001 1D 00011101 > > > > 0011 1011 > > 3 B > > > > Yet, you run this code with those ; REMOVE THIS LINE , it won't > work! I > > don't know why the RLF shift is NOT CONSISTANT. Please this has > really > > stumped me.. > > > > title "FirstAp.asm" > > > > ; Tony PETROSKI > > ; Nov, 2003 > > > > LIST R=DEC > > INCLUDE "p16f84a.inc" > > > > ; Register usage > > > > CBLOCK 0x020 ; start registers at end of values > > k, tempV > > ENDC > > > > > > START org 0000h > > > > ; clear file registers > > clrw > > clrf PORTB > > clrf k > > clrf tempV > > > > ; set tris & ports > > movlw 0x000 > > bsf STATUS, RP0 ; bank 1 > > movwf TRISB ^ 0x080 > > bcf STATUS, RP0 ; bank0 > > clrf PORTB > > > > ; initialise variables i, j, k > > movlw 0x008 > > movwf k ; w = 5 > > > > ; mainRoutine > > mainR movlw 0x03B > > movwf tempV > > call sendBt > > > > movlw 0x029 ; REMOVE THIS LINE > > movwf tempV ; REMOVE THIS LINE > > call sendBt ; REMOVE THIS LINE > > > > movlw 0x000 ; REMOVE THIS LINE > > movwf tempV ; REMOVE THIS LINE > > call sendBt ; REMOVE THIS LINE > > > > > > ; How can i come back to this mainroutine properly ? > > > > > > goto $ ; loop forever > > > > > > sendBt rlf tempV, w ; left shift tempV > > > > movwf tempV > > > > btfsc STATUS, C > > goto bitSet > > bcf PORTB, 7 > > goto deCremt > > bitSet bsf PORTB, IRP > > > > deCremt decfsz k, f ; decrement k until = 0 > > goto sendBt > > > > > > > > > > > > end > > > > > > > > > > > > ----- Original Message ----- > > From: "rtstofer" <rstofer@p...> > > To: <> > > Sent: Tuesday, November 18, 2003 12:35 AM > > Subject: [piclist] Re: Stream ouput on RB7 pin using 16f84.. > > > > > > > > > > Because the PIC doesn't have conditional jump instructions, IF- > THEN- > > > ELSE looks a little ugly: > > > > > > BTFSC STATUS,C ; skip the next GOTO if C is clear > > > GOTO CARRY_SET > > > > > > BCF PORTB,7 ; carry was clear so clear the output bit > > > GOTO ALL_DONE > > > > > > CARRY_SET: > > > BSF PORTB,7 ; carry was set so set the output bit > > > > > > ALL_DONE: > > > .... ; the rest of the code > > > > > > > > > Asynchronous communication occurs without a specific clock > because > > > both the receiver and transmitter agree to a baud rate. The > start > > > bit allows the receiver to synchronize with the transmitter and > the > > > stop bit validates the transmission of one byte. > > > > > > Synchronous communication occurs with a clock signal sent along > with > > > the data signal. Like RB6 in your case. This is the easiest to > > > implement: set the data bit and toggle the clock. Start and > stop > > > bits can be added to the data stream to simplify synchronizing > the > > > receiver. > > > > > > Various PICS have both an asynchronous and synchronous > transceiver - > > > are you sure you can't use them? > > > > > > --- In , "Tony PETROSKI" > > > <fivpenguin3000@y...> wrote: > > > > Thankyou very much for your valued response rtstofer! > > > > > > > > It's helped me out a lot! I have gone through the pointers & > all > > > makes > > > > sense. > > > > > > > > Just one little hick-up, & i will search through the piclist > FAQ > > > but just on > > > > point 5. Its sort of a catch 22 situation for me.... > > > > > > > > If i test for the Carry bit using BTFSS or BTFSC i.e. BTFSS > > > STATUS, C > > > > > > > > If set, then i must BSF PORTB, RB7 which is ok. But if its > clear > > > then i am > > > > stuck clearing & setting. > > > > Even if i try BTFSC, i get myself in the same predicament! > > > > > > > > so... > > > > > > > > btfss status, c > > > > bcf portb, rb7 > > > > bsf portb, rb7 > > > > > > > > > > > > So essentially, the answer here is, how do i do IF/ELSE > statements > > > in PIC > > > > assembly ? > > > > > > > > > > > > BTW:) OK. You brought up some important questions. Firstly, i > need > > > to find > > > > out the start/stop bits. As far as clocking goes, RB6 is the > clock > > > signal. > > > > This setup is a goldwafer card. RB7 is data, RB6 is clock. But > i > > > am a > > > > beginner in PIC micro's but i love it to say the least. I > wonder > > > if its > > > > possible to time the clock signals using RB6 as input versus a > > > time axis. I > > > > don't know what timers PIC's have which may be able to measure > then > > > > calculate the clock speed in MHz. Oh, maybe i can set a loop > which > > > reads > > > > input 100 times but i need some timer in the background...... > > > > > > > > > > > > > > > > > > > > cheers > > > > > > > > > > > > tony > > > > > > > > > > > > > > > > > > > > ----- Original Message ----- > > > > From: "rtstofer" <rstofer@p...> > > > > To: <> > > > > Sent: Monday, November 17, 2003 11:05 AM > > > > Subject: [piclist] Re: Stream ouput on RB7 pin using 16f84.. > > > > > > > > > > > > > Since you are trying to send the data in a serial manner the > > > easiest > > > > > thing would be to: > > > > > > > > > > 1) load first byte to a temp location > > > > > 2) call subroutine > > > > > 3) load second byte to a temp location > > > > > 4) call subroutine > > > > > > > > > > subroutine: > > > > > 1) set a loop counter to 8 (bits to process) > > > > > 2) load byte from temp location to W > > > > > 3) shift left into carry (RLF) > > > > > 4) store W back in temp location > > > > > 5) if Carry is set, set PORTB.7 else clear PORTB.7 > > > > > 6) decrement loop counter > > > > > 7) if loop counter > 0 goto 2 > > > > > 8) return > > > > > > > > > > The problem with such a scheme is clocking. How does the > > > receiver > > > > > of this bit stream know that 2 adjacent 0's (or 1's) are two > > > > > distinct bits and not just one long bit? > > > > > > > > > > --- In , "fivpenguin3000" > > > > > <fivpenguin3000@y...> wrote: > > > > > > Hi Guys, > > > > > > > > > > > > > > > > > > I have been stuck on this problem for 3 days so I hope i > can > > > get > > > > > > some input from this group. > > > > > > > > > > > > Issue: > > > > > > To send 2 bytes eg. say 0x03B via RB7 pin. > > > > > > > > > > > > KNOWN: I can test for (1) or (0) on RB7 pin for start-up. > > > > > > Setting trisb & portb are no problem. > > > > > > saving w reg to File registers are no problem. > > > > > > > > > > > > Problem: What sort of code will i basically need, to send > 3Bh > > > via > > > > > > rb7 ? What is this method call ? > > > > > > > > > > > > > > > > > > I can provide snippets of my code if required. > > > > > > > > > > > > > > > > > > thanks in advance, > > > > > > > > > > > > > > > > > > tony > > > > > > > > > > > > > > > > > > > > to unsubscribe, go to http://www.yahoogroups.com and follow > the > > > > instructions > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > to unsubscribe, go to http://www.yahoogroups.com and follow the > > instructions > > > > > > > > > > > > > to unsubscribe, go to http://www.yahoogroups.com and follow the instructions |
|
Whoops Sorry rtstofer! If i add the movlw k to the sendBt routine it does work correctly. Why did this happen ? What linkage with the k variable & rlf is there that i missed ? All i can think of is if the decsz command might have something to do with it! I never read anything about this linkage ? Thankyou very much!!!! Now i can play more! Yes, i can use other PICmicro chips but it's just that i have a few 16f84 goldwafers lying about. I do intend to progress to the 16f877 & well, i'll see about the others later....I also bought the CSS C compiler. I will try to do code in assembly & in 'C' & then compare......... ----- Original Message ----- From: "rtstofer" <> To: <> Sent: Tuesday, November 18, 2003 1:03 PM Subject: [piclist] Re: Stream ouput on RB7 pin using 16f84.. > > You have to initialize the variable 'k' within the sendBt subroutine > before you start dealing with the RLF stuff. > --- In , "Tony PETROSKI" > <fivpenguin3000@y...> wrote: > > Oh, thanks again rtstofer!!! I worked that out late last > > night.......Unfortunanetly, i have this really annoying BUG! I > spent hours > > last night trying to work it out! It's sent me crazy...i don't > know if there > > is a solution. I will post my current code. In the code, i have > written a > > comment ; remove this line. Now if make any arbitary changes like > add extra > > variables in CBLOCK or remove these lines the RLF shift operation > doesn't > > work right. The following table shows how i think the RLF should > work after > > 8 increments.. > > > > status 00011000 3B 00111011 > > > > 0status 00011000 76 01110110 > > 1status 00011000 EC 11101100 > > 2status 00011001 D8 11011000 > > 3status 00011001 B1 10110001 > > 4status 00011001 63 01100011 > > 5status 00011000 C7 11000111 > > 6status 00011001 8E 10001110 > > 7status 00011001 1D 00011101 > > > > 0011 1011 > > 3 B > > > > Yet, you run this code with those ; REMOVE THIS LINE , it won't > work! I > > don't know why the RLF shift is NOT CONSISTANT. Please this has > really > > stumped me.. > > > > title "FirstAp.asm" > > > > ; Tony PETROSKI > > ; Nov, 2003 > > > > LIST R=DEC > > INCLUDE "p16f84a.inc" > > > > ; Register usage > > > > CBLOCK 0x020 ; start registers at end of values > > k, tempV > > ENDC > > > > > > START org 0000h > > > > ; clear file registers > > clrw > > clrf PORTB > > clrf k > > clrf tempV > > > > ; set tris & ports > > movlw 0x000 > > bsf STATUS, RP0 ; bank 1 > > movwf TRISB ^ 0x080 > > bcf STATUS, RP0 ; bank0 > > clrf PORTB > > > > ; initialise variables i, j, k > > movlw 0x008 > > movwf k ; w = 5 > > > > ; mainRoutine > > mainR movlw 0x03B > > movwf tempV > > call sendBt > > > > movlw 0x029 ; REMOVE THIS LINE > > movwf tempV ; REMOVE THIS LINE > > call sendBt ; REMOVE THIS LINE > > > > movlw 0x000 ; REMOVE THIS LINE > > movwf tempV ; REMOVE THIS LINE > > call sendBt ; REMOVE THIS LINE > > > > > > ; How can i come back to this mainroutine properly ? > > > > > > goto $ ; loop forever > > > > > > sendBt rlf tempV, w ; left shift tempV > > > > movwf tempV > > > > btfsc STATUS, C > > goto bitSet > > bcf PORTB, 7 > > goto deCremt > > bitSet bsf PORTB, IRP > > > > deCremt decfsz k, f ; decrement k until = 0 > > goto sendBt > > > > > > > > > > > > end > > > > > > > > > > > > ----- Original Message ----- > > From: "rtstofer" <rstofer@p...> > > To: <> > > Sent: Tuesday, November 18, 2003 12:35 AM > > Subject: [piclist] Re: Stream ouput on RB7 pin using 16f84.. > > > > > > > > > > Because the PIC doesn't have conditional jump instructions, IF- > THEN- > > > ELSE looks a little ugly: > > > > > > BTFSC STATUS,C ; skip the next GOTO if C is clear > > > GOTO CARRY_SET > > > > > > BCF PORTB,7 ; carry was clear so clear the output bit > > > GOTO ALL_DONE > > > > > > CARRY_SET: > > > BSF PORTB,7 ; carry was set so set the output bit > > > > > > ALL_DONE: > > > .... ; the rest of the code > > > > > > > > > Asynchronous communication occurs without a specific clock > because > > > both the receiver and transmitter agree to a baud rate. The > start > > > bit allows the receiver to synchronize with the transmitter and > the > > > stop bit validates the transmission of one byte. > > > > > > Synchronous communication occurs with a clock signal sent along > with > > > the data signal. Like RB6 in your case. This is the easiest to > > > implement: set the data bit and toggle the clock. Start and > stop > > > bits can be added to the data stream to simplify synchronizing > the > > > receiver. > > > > > > Various PICS have both an asynchronous and synchronous > transceiver - > > > are you sure you can't use them? > > > > > > --- In , "Tony PETROSKI" > > > <fivpenguin3000@y...> wrote: > > > > Thankyou very much for your valued response rtstofer! > > > > > > > > It's helped me out a lot! I have gone through the pointers & > all > > > makes > > > > sense. > > > > > > > > Just one little hick-up, & i will search through the piclist > FAQ > > > but just on > > > > point 5. Its sort of a catch 22 situation for me.... > > > > > > > > If i test for the Carry bit using BTFSS or BTFSC i.e. BTFSS > > > STATUS, C > > > > > > > > If set, then i must BSF PORTB, RB7 which is ok. But if its > clear > > > then i am > > > > stuck clearing & setting. > > > > Even if i try BTFSC, i get myself in the same predicament! > > > > > > > > so... > > > > > > > > btfss status, c > > > > bcf portb, rb7 > > > > bsf portb, rb7 > > > > > > > > > > > > So essentially, the answer here is, how do i do IF/ELSE > statements > > > in PIC > > > > assembly ? > > > > > > > > > > > > BTW:) OK. You brought up some important questions. Firstly, i > need > > > to find > > > > out the start/stop bits. As far as clocking goes, RB6 is the > clock > > > signal. > > > > This setup is a goldwafer card. RB7 is data, RB6 is clock. But > i > > > am a > > > > beginner in PIC micro's but i love it to say the least. I > wonder > > > if its > > > > possible to time the clock signals using RB6 as input versus a > > > time axis. I > > > > don't know what timers PIC's have which may be able to measure > then > > > > calculate the clock speed in MHz. Oh, maybe i can set a loop > which > > > reads > > > > input 100 times but i need some timer in the background...... > > > > > > > > > > > > > > > > > > > > cheers > > > > > > > > > > > > tony > > > > > > > > > > > > > > > > > > > > ----- Original Message ----- > > > > From: "rtstofer" <rstofer@p...> > > > > To: <> > > > > Sent: Monday, November 17, 2003 11:05 AM > > > > Subject: [piclist] Re: Stream ouput on RB7 pin using 16f84.. > > > > > > > > > > > > > Since you are trying to send the data in a serial manner the > > > easiest > > > > > thing would be to: > > > > > > > > > > 1) load first byte to a temp location > > > > > 2) call subroutine > > > > > 3) load second byte to a temp location > > > > > 4) call subroutine > > > > > > > > > > subroutine: > > > > > 1) set a loop counter to 8 (bits to process) > > > > > 2) load byte from temp location to W > > > > > 3) shift left into carry (RLF) > > > > > 4) store W back in temp location > > > > > 5) if Carry is set, set PORTB.7 else clear PORTB.7 > > > > > 6) decrement loop counter > > > > > 7) if loop counter > 0 goto 2 > > > > > 8) return > > > > > > > > > > The problem with such a scheme is clocking. How does the > > > receiver > > > > > of this bit stream know that 2 adjacent 0's (or 1's) are two > > > > > distinct bits and not just one long bit? > > > > > > > > > > --- In , "fivpenguin3000" > > > > > <fivpenguin3000@y...> wrote: > > > > > > Hi Guys, > > > > > > > > > > > > > > > > > > I have been stuck on this problem for 3 days so I hope i > can > > > get > > > > > > some input from this group. > > > > > > > > > > > > Issue: > > > > > > To send 2 bytes eg. say 0x03B via RB7 pin. > > > > > > > > > > > > KNOWN: I can test for (1) or (0) on RB7 pin for start-up. > > > > > > Setting trisb & portb are no problem. > > > > > > saving w reg to File registers are no problem. > > > > > > > > > > > > Problem: What sort of code will i basically need, to send > 3Bh > > > via > > > > > > rb7 ? What is this method call ? > > > > > > > > > > > > > > > > > > I can provide snippets of my code if required. > > > > > > > > > > > > > > > > > > thanks in advance, > > > > > > > > > > > > > > > > > > tony > > > > > > > > > > > > > > > > > > > > to unsubscribe, go to http://www.yahoogroups.com and follow > the > > > > instructions > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > to unsubscribe, go to http://www.yahoogroups.com and follow the > > instructions > > > > > > > > > > > > > to unsubscribe, go to http://www.yahoogroups.com and follow the instructions |
|
|
|
The only thing i can think of is that local variables must be initialised in each subroutine. I have done c, & c++ & i know that depending on your function requirements, you can set variables accordingly.i.e. local or global. I thought that by using CBLOCK & putting the value into the variables in main, it was global. When i checked the 'FIle Register', i could see this happen successfully as i was stepping throughout the code. ----- Original Message ----- From: "Tony PETROSKI" <> To: <> Sent: Tuesday, November 18, 2003 1:44 PM Subject: Re: [piclist] Re: Stream ouput on RB7 pin using 16f84.. > Whoops Sorry rtstofer! > > If i add the movlw k to the sendBt routine it does work correctly. Why > did this happen ? What linkage with the k variable & rlf is there that i > missed ? > > All i can think of is if the decsz command might have something to do with > it! I never read anything about this linkage ? > > > Thankyou very much!!!! > Now i can play more! Yes, i can use other PICmicro chips but it's just that > i have a few 16f84 goldwafers lying about. I do intend to progress to the > 16f877 & well, i'll see about the others later....I also bought the CSS C > compiler. I will try to do code in assembly & in 'C' & then compare......... > > > ----- Original Message ----- > From: "rtstofer" <> > To: <> > Sent: Tuesday, November 18, 2003 1:03 PM > Subject: [piclist] Re: Stream ouput on RB7 pin using 16f84.. > > > > You have to initialize the variable 'k' within the sendBt subroutine > > before you start dealing with the RLF stuff. > > > > > > --- In , "Tony PETROSKI" > > <fivpenguin3000@y...> wrote: > > > Oh, thanks again rtstofer!!! I worked that out late last > > > night.......Unfortunanetly, i have this really annoying BUG! I > > spent hours > > > last night trying to work it out! It's sent me crazy...i don't > > know if there > > > is a solution. I will post my current code. In the code, i have > > written a > > > comment ; remove this line. Now if make any arbitary changes like > > add extra > > > variables in CBLOCK or remove these lines the RLF shift operation > > doesn't > > > work right. The following table shows how i think the RLF should > > work after > > > 8 increments.. > > > > > > status 00011000 3B 00111011 > > > > > > 0status 00011000 76 01110110 > > > 1status 00011000 EC 11101100 > > > 2status 00011001 D8 11011000 > > > 3status 00011001 B1 10110001 > > > 4status 00011001 63 01100011 > > > 5status 00011000 C7 11000111 > > > 6status 00011001 8E 10001110 > > > 7status 00011001 1D 00011101 > > > > > > 0011 1011 > > > 3 B > > > > > > Yet, you run this code with those ; REMOVE THIS LINE , it won't > > work! I > > > don't know why the RLF shift is NOT CONSISTANT. Please this has > > really > > > stumped me.. > > > > > > title "FirstAp.asm" > > > > > > ; Tony PETROSKI > > > ; Nov, 2003 > > > > > > LIST R=DEC > > > INCLUDE "p16f84a.inc" > > > > > > ; Register usage > > > > > > CBLOCK 0x020 ; start registers at end of values > > > k, tempV > > > ENDC > > > > > > > > > START org 0000h > > > > > > ; clear file registers > > > clrw > > > clrf PORTB > > > clrf k > > > clrf tempV > > > > > > ; set tris & ports > > > movlw 0x000 > > > bsf STATUS, RP0 ; bank 1 > > > movwf TRISB ^ 0x080 > > > bcf STATUS, RP0 ; bank0 > > > clrf PORTB > > > > > > ; initialise variables i, j, k > > > movlw 0x008 > > > movwf k ; w = 5 > > > > > > ; mainRoutine > > > mainR movlw 0x03B > > > movwf tempV > > > call sendBt > > > > > > movlw 0x029 ; REMOVE THIS LINE > > > movwf tempV ; REMOVE THIS LINE > > > call sendBt ; REMOVE THIS LINE > > > > > > movlw 0x000 ; REMOVE THIS LINE > > > movwf tempV ; REMOVE THIS LINE > > > call sendBt ; REMOVE THIS LINE > > > > > > > > > ; How can i come back to this mainroutine properly ? > > > > > > > > > goto $ ; loop forever > > > > > > > > > sendBt rlf tempV, w ; left shift tempV > > > > > > movwf tempV > > > > > > btfsc STATUS, C > > > goto bitSet > > > bcf PORTB, 7 > > > goto deCremt > > > bitSet bsf PORTB, IRP > > > > > > deCremt decfsz k, f ; decrement k until = 0 > > > goto sendBt > > > > > > > > > > > > > > > > > > end > > > > > > > > > > > > > > > > > > ----- Original Message ----- > > > From: "rtstofer" <rstofer@p...> > > > To: <> > > > Sent: Tuesday, November 18, 2003 12:35 AM > > > Subject: [piclist] Re: Stream ouput on RB7 pin using 16f84.. > > > > > > > > > > > > > > Because the PIC doesn't have conditional jump instructions, IF- > > THEN- > > > > ELSE looks a little ugly: > > > > > > > > BTFSC STATUS,C ; skip the next GOTO if C is clear > > > > GOTO CARRY_SET > > > > > > > > BCF PORTB,7 ; carry was clear so clear the output bit > > > > GOTO ALL_DONE > > > > > > > > CARRY_SET: > > > > BSF PORTB,7 ; carry was set so set the output bit > > > > > > > > ALL_DONE: > > > > .... ; the rest of the code > > > > > > > > > > > > Asynchronous communication occurs without a specific clock > > because > > > > both the receiver and transmitter agree to a baud rate. The > > start > > > > bit allows the receiver to synchronize with the transmitter and > > the > > > > stop bit validates the transmission of one byte. > > > > > > > > Synchronous communication occurs with a clock signal sent along > > with > > > > the data signal. Like RB6 in your case. This is the easiest to > > > > implement: set the data bit and toggle the clock. Start and > > stop > > > > bits can be added to the data stream to simplify synchronizing > > the > > > > receiver. > > > > > > > > Various PICS have both an asynchronous and synchronous > > transceiver - > > > > are you sure you can't use them? > > > > > > > > --- In , "Tony PETROSKI" > > > > <fivpenguin3000@y...> wrote: > > > > > Thankyou very much for your valued response rtstofer! > > > > > > > > > > It's helped me out a lot! I have gone through the pointers & > > all > > > > makes > > > > > sense. > > > > > > > > > > Just one little hick-up, & i will search through the piclist > > FAQ > > > > but just on > > > > > point 5. Its sort of a catch 22 situation for me.... > > > > > > > > > > If i test for the Carry bit using BTFSS or BTFSC i.e. BTFSS > > > > STATUS, C > > > > > > > > > > If set, then i must BSF PORTB, RB7 which is ok. But if its > > clear > > > > then i am > > > > > stuck clearing & setting. > > > > > Even if i try BTFSC, i get myself in the same predicament! > > > > > > > > > > so... > > > > > > > > > > btfss status, c > > > > > bcf portb, rb7 > > > > > bsf portb, rb7 > > > > > > > > > > > > > > > So essentially, the answer here is, how do i do IF/ELSE > > statements > > > > in PIC > > > > > assembly ? > > > > > > > > > > > > > > > BTW:) OK. You brought up some important questions. Firstly, i > > need > > > > to find > > > > > out the start/stop bits. As far as clocking goes, RB6 is the > > clock > > > > signal. > > > > > This setup is a goldwafer card. RB7 is data, RB6 is clock. But > > i > > > > am a > > > > > beginner in PIC micro's but i love it to say the least. I > > wonder > > > > if its > > > > > possible to time the clock signals using RB6 as input versus a > > > > time axis. I > > > > > don't know what timers PIC's have which may be able to measure > > then > > > > > calculate the clock speed in MHz. Oh, maybe i can set a loop > > which > > > > reads > > > > > input 100 times but i need some timer in the background...... > > > > > > > > > > > > > > > > > > > > > > > > > cheers > > > > > > > > > > > > > > > tony > > > > > > > > > > > > > > > > > > > > > > > > > ----- Original Message ----- > > > > > From: "rtstofer" <rstofer@p...> > > > > > To: <> > > > > > Sent: Monday, November 17, 2003 11:05 AM > > > > > Subject: [piclist] Re: Stream ouput on RB7 pin using 16f84.. > > > > > > > > > > > > > > > > Since you are trying to send the data in a serial manner the > > > > easiest > > > > > > thing would be to: > > > > > > > > > > > > 1) load first byte to a temp location > > > > > > 2) call subroutine > > > > > > 3) load second byte to a temp location > > > > > > 4) call subroutine > > > > > > > > > > > > subroutine: > > > > > > 1) set a loop counter to 8 (bits to process) > > > > > > 2) load byte from temp location to W > > > > > > 3) shift left into carry (RLF) > > > > > > 4) store W back in temp location > > > > > > 5) if Carry is set, set PORTB.7 else clear PORTB.7 > > > > > > 6) decrement loop counter > > > > > > 7) if loop counter > 0 goto 2 > > > > > > 8) return > > > > > > > > > > > > The problem with such a scheme is clocking. How does the > > > > receiver > > > > > > of this bit stream know that 2 adjacent 0's (or 1's) are two > > > > > > distinct bits and not just one long bit? > > > > > > > > > > > > --- In , "fivpenguin3000" > > > > > > <fivpenguin3000@y...> wrote: > > > > > > > Hi Guys, > > > > > > > > > > > > > > > > > > > > > I have been stuck on this problem for 3 days so I hope i > > can > > > > get > > > > > > > some input from this group. > > > > > > > > > > > > > > Issue: > > > > > > > To send 2 bytes eg. say 0x03B via RB7 pin. > > > > > > > > > > > > > > KNOWN: I can test for (1) or (0) on RB7 pin for start-up. > > > > > > > Setting trisb & portb are no problem. > > > > > > > saving w reg to File registers are no problem. > > > > > > > > > > > > > > Problem: What sort of code will i basically need, to send > > 3Bh > > > > via > > > > > > > rb7 ? What is this method call ? > > > > > > > > > > > > > > > > > > > > > I can provide snippets of my code if required. > > > > > > > > > > > > > > > > > > > > > thanks in advance, > > > > > > > > > > > > > > > > > > > > > tony > > > > > > > > > > > > > > > > > > > > > > > > to unsubscribe, go to http://www.yahoogroups.com and follow > > the > > > > > instructions > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > to unsubscribe, go to http://www.yahoogroups.com and follow the > > > instructions > > > > > > > > > > > > > > > > > > > > > > > > to unsubscribe, go to http://www.yahoogroups.com and follow the > instructions > > > > > > > > > to unsubscribe, go to http://www.yahoogroups.com and follow the instructions |
|
There is NO linkage between 'k' and RLF. Think about what happens on the second call to sendBt: 'k' was already 0 from the previous call so when we decrement the counter it goes to 255, then 254, the 253, etc. There will be 256 shifts during the second call - not the kind of thing you were expecting. You know, the simulator in MPLAB can let you watch how your code executes. It might be useful. You can make complex code more readable with C than with ASM but... If the algorithm is defective neither work very well and C is a LOT more difficult to debug. It is much more difficult to see what is happening at the hardware level and to do it you have to look at the assembly code anyway. In my opinion, and there will be many others with a different opinion, get a solid grip on the 35 instructions of assembly code before moving on to C. Some will suggest you skip the whole process and move directly to some variant of Basic - PicBasic seems a popular choice. Be certain you understand each instruction and EXACTLY what it does, know how to implement the various control constructs such as IF-THEN- ELSE, WHILE-WEND, REPEAT-UNTIL and FOR-NEXT, and array indexing using FSR/INDF and table lookup using RETLW (there are some gotcha's here). This in addition to understanding how to initialize and use each hardware block - timers, serial I/O, PWM, A/D and interrupts. There is a lot of stuff to learn but, in my opinion, it is easier to learn in assembly. That is because you create a line of code for every operation required to use every device. You deal directly with initialization and bit twiddling. You will need to develop a few 'tools' such as serial I/O to send debugging information to the console. Maybe you would have enough room to add an LCD and keypad. There are 16F877 prototype boards that have these included. Enough rambling - you need to decide at what level you want to understand the hardware and software. The PIC is a perfect place to learn at a very detailed level. |
|
|
|
so then why not just stick with the 35 instructions versus using the mnemonics (I think that's what MPLab calls them, I don't have my reference here) such as SKPNC, etc? And why not just write to 0x81 versus using the include file and calling it option_reg? IMO a lot of the 'extras' just add to the haze. I started off doing it the 'hard way' and now still make notes of stuff I need to figure out, like "list" and "page" commands, stuff that's not part of the 35 instructions. And I have yet to convert all the way to cblock,using the inc mnemonics, etc. Oh, BTW, what does "list" and "page" do? --- rtstofer <> wrote: > > There is NO linkage between 'k' and RLF. Think about what happens > on the second call to sendBt: 'k' was already 0 from the previous > call so when we decrement the counter it goes to 255, then 254, the > 253, etc. There will be 256 shifts during the second call - not the > kind of thing you were expecting. > > You know, the simulator in MPLAB can let you watch how your code > executes. It might be useful. > > You can make complex code more readable with C than with ASM but... > If the algorithm is defective neither work very well and C is a LOT > more difficult to debug. It is much more difficult to see what is > happening at the hardware level and to do it you have to look at the > assembly code anyway. In my opinion, and there will be many others > with a different opinion, get a solid grip on the 35 instructions of > assembly code before moving on to C. Some will suggest you skip the > whole process and move directly to some variant of Basic - PicBasic > seems a popular choice. > > Be certain you understand each instruction and EXACTLY what it does, > know how to implement the various control constructs such as IF-THEN- > ELSE, WHILE-WEND, REPEAT-UNTIL and FOR-NEXT, and array indexing > using FSR/INDF and table lookup using RETLW (there are some gotcha's > here). This in addition to understanding how to initialize and use > each hardware block - timers, serial I/O, PWM, A/D and interrupts. > > There is a lot of stuff to learn but, in my opinion, it is easier to > learn in assembly. That is because you create a line of code for > every operation required to use every device. You deal directly > with initialization and bit twiddling. > > You will need to develop a few 'tools' such as serial I/O to send > debugging information to the console. Maybe you would have enough > room to add an LCD and keypad. There are 16F877 prototype boards > that have these included. > > Enough rambling - you need to decide at what level you want to > understand the hardware and software. The PIC is a perfect place to > learn at a very detailed level. __________________________________ |
|
|
|
Then why bother with instruction names at all. why not just use hex codes??? then that pesky f vs b would be clear if its a 0 or 1. (ok, exit sarcasm mode...) These psuedo instructions are actually quite useful. Out of habit, I dont use things like skpnc but its much more obvious as to the intent than btfss status,c (lets see, that skips if there was a carry...) Also, consider when some one picks up your code and tries to figure it out. Like bsf 0x81,7 vs bsf OPTIONS_REG,RBPU seems pretty obvious to me. Especially for those regs that move around on the different PICs If I had to maintain a piece of code like that, I'd think about about revenge... :) then consider you picking up your own code in 6 months or a year to make a fix. Comments are helpful but when the code is misbehaving, the comments are suspect. I suspect we agree that there is no substitute for understanding the processor you are programing, though. But, it boils down to matter of choice. Phil --- In , John Remington <jrem123@y...> wrote: > so then why not just stick with the 35 instructions versus using the > mnemonics (I think that's what MPLab calls them, I don't have my > reference here) such as SKPNC, etc? And why not just write to 0x81 > versus using the include file and calling it option_reg? > > IMO a lot of the 'extras' just add to the haze. I started off doing it > the 'hard way' and now still make notes of stuff I need to figure out, > like "list" and "page" commands, stuff that's not part of the 35 > instructions. And I have yet to convert all the way to cblock,using > the inc mnemonics, etc. > > Oh, BTW, what does "list" and "page" do? > --- rtstofer <rstofer@p...> wrote: > > > > There is NO linkage between 'k' and RLF. Think about what happens > > on the second call to sendBt: 'k' was already 0 from the previous > > call so when we decrement the counter it goes to 255, then 254, the > > 253, etc. There will be 256 shifts during the second call - not the > > kind of thing you were expecting. > > > > You know, the simulator in MPLAB can let you watch how your code > > executes. It might be useful. > > > > You can make complex code more readable with C than with ASM but... > > If the algorithm is defective neither work very well and C is a LOT > > more difficult to debug. It is much more difficult to see what is > > happening at the hardware level and to do it you have to look at the > > assembly code anyway. In my opinion, and there will be many others > > with a different opinion, get a solid grip on the 35 instructions of > > assembly code before moving on to C. Some will suggest you skip the > > whole process and move directly to some variant of Basic - PicBasic > > seems a popular choice. > > > > Be certain you understand each instruction and EXACTLY what it does, > > know how to implement the various control constructs such as IF- THEN- > > ELSE, WHILE-WEND, REPEAT-UNTIL and FOR-NEXT, and array indexing > > using FSR/INDF and table lookup using RETLW (there are some gotcha's > > here). This in addition to understanding how to initialize and use > > each hardware block - timers, serial I/O, PWM, A/D and interrupts. > > > > There is a lot of stuff to learn but, in my opinion, it is easier to > > learn in assembly. That is because you create a line of code for > > every operation required to use every device. You deal directly > > with initialization and bit twiddling. > > > > You will need to develop a few 'tools' such as serial I/O to send > > debugging information to the console. Maybe you would have enough > > room to add an LCD and keypad. There are 16F877 prototype boards > > that have these included. > > > > Enough rambling - you need to decide at what level you want to > > understand the hardware and software. The PIC is a perfect place to > > learn at a very detailed level. > > > > > > __________________________________ |
|
Yes, Microchip did define some aliases to help with the not very obvious way that btfss and btfsc handle branching. They are helpful I suppose but they are not machine instructions. They are macros or aliases. Page just inserts a page in the output listing. List is much more complex. Both are detailed in the MPASM help file. And, yes, macros too help us move a level above machine instruction mnemonics. But there are still 35 machine instructions. And I'll be darned if I can figure out how a person could create or use macros without first understanding the low level 35. IMO you have to start at the beginning and work outward. --- In , John Remington <jrem123@y...> wrote: > so then why not just stick with the 35 instructions versus using the > mnemonics (I think that's what MPLab calls them, I don't have my > reference here) such as SKPNC, etc? And why not just write to 0x81 > versus using the include file and calling it option_reg? > > IMO a lot of the 'extras' just add to the haze. I started off doing it > the 'hard way' and now still make notes of stuff I need to figure out, > like "list" and "page" commands, stuff that's not part of the 35 > instructions. And I have yet to convert all the way to cblock,using > the inc mnemonics, etc. > > Oh, BTW, what does "list" and "page" do? > --- rtstofer <rstofer@p...> wrote: > > > > There is NO linkage between 'k' and RLF. Think about what happens > > on the second call to sendBt: 'k' was already 0 from the previous > > call so when we decrement the counter it goes to 255, then 254, the > > 253, etc. There will be 256 shifts during the second call - not the > > kind of thing you were expecting. > > > > You know, the simulator in MPLAB can let you watch how your code > > executes. It might be useful. > > > > You can make complex code more readable with C than with ASM but... > > If the algorithm is defective neither work very well and C is a LOT > > more difficult to debug. It is much more difficult to see what is > > happening at the hardware level and to do it you have to look at the > > assembly code anyway. In my opinion, and there will be many others > > with a different opinion, get a solid grip on the 35 instructions of > > assembly code before moving on to C. Some will suggest you skip the > > whole process and move directly to some variant of Basic - PicBasic > > seems a popular choice. > > > > Be certain you understand each instruction and EXACTLY what it does, > > know how to implement the various control constructs such as IF- THEN- > > ELSE, WHILE-WEND, REPEAT-UNTIL and FOR-NEXT, and array indexing > > using FSR/INDF and table lookup using RETLW (there are some gotcha's > > here). This in addition to understanding how to initialize and use > > each hardware block - timers, serial I/O, PWM, A/D and interrupts. > > > > There is a lot of stuff to learn but, in my opinion, it is easier to > > learn in assembly. That is because you create a line of code for > > every operation required to use every device. You deal directly > > with initialization and bit twiddling. > > > > You will need to develop a few 'tools' such as serial I/O to send > > debugging information to the console. Maybe you would have enough > > room to add an LCD and keypad. There are 16F877 prototype boards > > that have these included. > > > > Enough rambling - you need to decide at what level you want to > > understand the hardware and software. The PIC is a perfect place to > > learn at a very detailed level. > > > > > > __________________________________ |