I want to shift out the 8 bit A/D conversion value for testing (read the a/d with my logic analyzer) but I can't find shift info. I want to do it with GCB code, not use any .h library.
Here is my existing code, the a/d read works but with the 8 pin chip I cannot output the full 8 bits in parallel..
So, serial shift seems a way to do it.
;
;============================my exsisting code================================
;Read A/D temp values of thermistors
'Pin values for 12F1840
;AN0 is pin 7
;AN1 IS PIN 6
;AN2 IS PIN 5
;AN3 IS PIN 3
#chip 12F1840, 8 'Pic 12F1840
#config MCLRE = Off, Osc = Int 'Turn off MCLR, select internal osc.
'WDT and LVP are disabled automatically
dim advalue1 as byte 'Location to store a/d value
dim LoopCount as Byte
Dir PORTA.4 In 'Set the pin 3 used for A/D conversion to an input
Dir porta.5 out ;Pin 2 for led test light
'Main routine starts
for LoopCount = 1 to 3 ;3 fast blink to show it is starting
set porta.5 on ;led on
Wait 250 ms
set porta.5 off ;led off
Wait 250 ms 'Wait
next loopcount
Do
advalue1 = ReadAD(AN3)
; if advalue1 > 127 then
; set porta.5 on ;led on
; else
; set porta.5 off ;led off
; end if
;Now shift a/d value out porta.5 ?????????????????????????????????????????????
;shift rtn will go here
;lsb or msb first for test
;
Wait 100 ms
Loop ;end of do loop
Last edit: Paul Haug 2017-04-16
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
It all depends upon what you want to see on your logic analyzer. Do you want the data formatted so that the Logic Analyzer can decode a protocol such as RS232 ? Or do you simply want to take a look and easily be able to see the 1's and 0's ?
I borrowed this protocol from DHT-11. A "1" is 100 us wide and a "0" is 25 us wide. There is 50 us between bits. This allows you to look at the signal and easily see the 1's and 0's. You will need to modify as needed for your particular chip.
Really great, thanks guys. Both rotate and individual bit banging, both what I need. Some how I couldn't find right shift/left shift in the code description, so now I know it's rotate.
.
On the rotate example above, STATUS.C I asume is the overflow/shiftout bit ? I will try to look it up as I need more clarification on this bit, is it common to all shifts, what does the "C" part stand for ?
EDIT:################
Found it now that I know to look for rotate, not shift. Also explains STATUS.C which is the carry bit.
Dang this GCB is addictive
END EDIT####################
Last edit: Paul Haug 2017-04-16
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Trying to find names that are logical but dont conlict with names used in core or hidden functions is a difficult balancing act. In this case FnLSL/FnLSR were chosen becouse LSL/LSR are reserved words (ASM mnemonics) so Fn was added as a prefix to indicate that it was a function that took an argument and returned a result allowing it to replace a variable. I think they have been depreciated, or will be, as Hugh was going to intergrate them into the core compiler. No harm in using them though and they arew actualy a wrapper for the rotate function.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Yes, thank you William. I did come across FnLSL and FnLSR but the nanes didn't mean anything so I skipped reading the details. Now I will go back and read. And your renaming scheme is great idea.
Thanks
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Me to Paul Haug. I saw Fn and thought function so skipped it. You don't need to set c on/off it seems with FnLSR. I found rotate first. Quicker than multiply/divide for bit values..multiply/divide 2,4,8,,128 it seems.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
You are correct, the Carry Flag is ignored in the FnLSL (Logic Shift Left) and FnLSR (Logic Shft Right) the two related functions FnASR (Arithmetic Shift Right) and FnROT are covered by the Rotate function, because they use The Carry Flag, so were not encoded as separate functions.
I am not sure why you ignored them because they are functions, Functions actually simplify your code, i.e.
'Set port direction
Dir PortB Out
'Set initial state of port (LED 4 on)
PORTB = b'00010000'
PortB = FnLSR(PortB) ' Shilft the LED one Bit to the Right
FnLSL, FnLSR and Rotate can all work on Word values too so you can multiply or divide by a binary number up to 32768.
Rotate is used where you want the Carry bit to influence the result, Logic Shift Functions are used where you don't want the low order bit rotating into the the high order bit as would happen, with disastrous results, in your division example above.
Cheers
Chris
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I want to shift out the 8 bit A/D conversion value for testing (read the a/d with my logic analyzer) but I can't find shift info. I want to do it with GCB code, not use any .h library.
Here is my existing code, the a/d read works but with the 8 pin chip I cannot output the full 8 bits in parallel..
So, serial shift seems a way to do it.
;
;============================my exsisting code================================
;Read A/D temp values of thermistors
'Pin values for 12F1840
;AN0 is pin 7
;AN1 IS PIN 6
;AN2 IS PIN 5
;AN3 IS PIN 3
#chip 12F1840, 8 'Pic 12F1840
#config MCLRE = Off, Osc = Int 'Turn off MCLR, select internal osc.
'WDT and LVP are disabled automatically
dim advalue1 as byte 'Location to store a/d value
dim LoopCount as Byte
Dir PORTA.4 In 'Set the pin 3 used for A/D conversion to an input
Dir porta.5 out ;Pin 2 for led test light
'Main routine starts
for LoopCount = 1 to 3 ;3 fast blink to show it is starting
set porta.5 on ;led on
Wait 250 ms
set porta.5 off ;led off
Wait 250 ms 'Wait
next loopcount
Do
advalue1 = ReadAD(AN3)
; if advalue1 > 127 then
; set porta.5 on ;led on
; else
; set porta.5 off ;led off
; end if
;Now shift a/d value out porta.5 ?????????????????????????????????????????????
;shift rtn will go here
;lsb or msb first for test
;
Wait 100 ms
Loop ;end of do loop
Last edit: Paul Haug 2017-04-16
Somthing like this will do it but you may need to introduce a dleay in the loop iff the Bits are too fast:
Cheers
Chris
It all depends upon what you want to see on your logic analyzer. Do you want the data formatted so that the Logic Analyzer can decode a protocol such as RS232 ? Or do you simply want to take a look and easily be able to see the 1's and 0's ?
I borrowed this protocol from DHT-11. A "1" is 100 us wide and a "0" is 25 us wide. There is 50 us between bits. This allows you to look at the signal and easily see the 1's and 0's. You will need to modify as needed for your particular chip.
Here is the same basic code but optimized by using rotate in a repeat loop
Really great, thanks guys. Both rotate and individual bit banging, both what I need. Some how I couldn't find right shift/left shift in the code description, so now I know it's rotate.
.
On the rotate example above, STATUS.C I asume is the overflow/shiftout bit ? I will try to look it up as I need more clarification on this bit, is it common to all shifts, what does the "C" part stand for ?
EDIT:################
Found it now that I know to look for rotate, not shift. Also explains STATUS.C which is the carry bit.
Dang this GCB is addictive
END EDIT####################
Last edit: Paul Haug 2017-04-16
Found it now that I know to look for rotate, not shift. Also explains STATUS.C which is the carry bit.
Dang this GCB is addictive.
Last edit: Paul Haug 2017-04-16
There are Shift functions but the names are somewhat confusing.
These are FnLSL and FnLSR.
Example: Databyte = FnLSL(Databyte ,2) '// shift left 2 places
Example: Databyte = FnLSR( Databyte, 4 ) '// Shift Right 4 places
Sometimes I "rename" these with a more intuitive/descriptive name using #define
*** To read more about FnLSL and FnLSR See Help > Command Referenece > Bitwise
Last edit: William Roth 2017-04-16
Trying to find names that are logical but dont conlict with names used in core or hidden functions is a difficult balancing act. In this case FnLSL/FnLSR were chosen becouse LSL/LSR are reserved words (ASM mnemonics) so Fn was added as a prefix to indicate that it was a function that took an argument and returned a result allowing it to replace a variable. I think they have been depreciated, or will be, as Hugh was going to intergrate them into the core compiler. No harm in using them though and they arew actualy a wrapper for the rotate function.
Not depreciated. Still need them.
If Help or IDE/Helpers need updating we need to restore.
😀
Yes, thank you William. I did come across FnLSL and FnLSR but the nanes didn't mean anything so I skipped reading the details. Now I will go back and read. And your renaming scheme is great idea.
Thanks
Me to Paul Haug. I saw Fn and thought function so skipped it. You don't need to set c on/off it seems with FnLSR. I found rotate first. Quicker than multiply/divide for bit values..multiply/divide 2,4,8,,128 it seems.
You are correct, the Carry Flag is ignored in the FnLSL (Logic Shift Left) and FnLSR (Logic Shft Right) the two related functions FnASR (Arithmetic Shift Right) and FnROT are covered by the Rotate function, because they use The Carry Flag, so were not encoded as separate functions.
I am not sure why you ignored them because they are functions, Functions actually simplify your code, i.e.
FnLSL, FnLSR and Rotate can all work on Word values too so you can multiply or divide by a binary number up to 32768.
Rotate is used where you want the Carry bit to influence the result, Logic Shift Functions are used where you don't want the low order bit rotating into the the high order bit as would happen, with disastrous results, in your division example above.
Cheers
Chris