So I thought you are supposed to load the high byte first for word variables in assembly? Here is an example where the high byte gets clobbered because the low byte is loaded first by gasm. Comment out ServoPeriod1 and uncomment the assembly language which loads the high byte first for the correct output.
#chip mega328, 16
#define USART_BAUD_RATE 9600
dir PortD.1 Out
Dim ServoPeriod1 as Word Alias OCR1AH, OCR1AL
Main:
ServoPeriod1 = 35
' ldi SYSVALUECOPY,0
' sts SERVOPERIOD1_H,SYSVALUECOPY
' ldi SYSVALUECOPY,35
' sts SERVOPERIOD1,SYSVALUECOPY
HSerPrint OCR1AH 'ServoPeriod1_H
HSerPrint ","
HSerPrint OCR1AL 'ServoPeriod1
HSerSend 13
HSerSend 10
wait 3 s
'ServoPeriod1 = 290
ldi SYSVALUECOPY,1
sts SERVOPERIOD1_H,SYSVALUECOPY
ldi SYSVALUECOPY,34
sts SERVOPERIOD1,SYSVALUECOPY
HSerPrint OCR1AH 'ServoPeriod1_H
HSerPrint ","
HSerPrint OCR1AL 'ServoPeriod1
HSerSend 13
HSerSend 10
wait 3 s
goto Main
P.S. oops using 95.008 or 97.01, no difference
Last edit: kent_twt4 2017-05-31
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
In assembler the low byte is always written first - always has been, This is why we need subs or functions to write certain buffered peripheral registers where the high byte must be written first
A good example might be the Settimer 1 from Timer.h.
If TMRNumber = 1 then
TMR1H = TMRValue_H
TMR1L = TMRValue
End If
.
We do have an Timer1 alias for TMR1H,, TMR1L but .....it is ONLY for reading the timer value, To write correctly to the TMR1H, TRM1L registers you must use the sub.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
O.K. thanks straightening that out for me William. Guess I just was so used to dealing with timers on the bit level, the Word Alias thing hadn't come up before. Onward and upward we go.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
So I thought you are supposed to load the high byte first for word variables in assembly? Here is an example where the high byte gets clobbered because the low byte is loaded first by gasm. Comment out ServoPeriod1 and uncomment the assembly language which loads the high byte first for the correct output.
P.S. oops using 95.008 or 97.01, no difference
Last edit: kent_twt4 2017-05-31
In assembler the low byte is always written first - always has been, This is why we need subs or functions to write certain buffered peripheral registers where the high byte must be written first
A good example might be the Settimer 1 from Timer.h.
.
We do have an Timer1 alias for TMR1H,, TMR1L but .....it is ONLY for reading the timer value, To write correctly to the TMR1H, TRM1L registers you must use the sub.
O.K. thanks straightening that out for me William. Guess I just was so used to dealing with timers on the bit level, the Word Alias thing hadn't come up before. Onward and upward we go.