Hello Forum,
This problem took a while to figure out.
I have been successfully using a Bootloader that includes display to a LCD for some time. I use PORTC for the data and PORTA for the control lines (Mega 644P in this case).
Bootloader code snippet:
[code:1:15d955b6f4]'=============================================
'Bootloader Mega644p
'Jul 15, 2013
'=============================================
$regfile = "m644pdef.dat"
$crystal = 8000000
$hwstack = 80 ' default use 32 for the hardware stack
$swstack = 64 ' default use 10 for the SW stack
$framesize = 64 ' default use 40 for the frame space
'
'======== [ Bootloader Config ] =================
Disable Interrupts 'we do not use ints
$loader = $7800
Const Bootloader_start = $7800
' Bootloader Hex $LOADERSIZE
' 8000 none 10000
' 7E00 FC00 $400
' 7C00 F800 $800
' 7800 F000 $1000
' 7000 E000 $2000
Const Maxwordbit = 7 'Z7 is maximum bit '
Const Maxword =(2 ^ Maxwordbit) * 2 '128
Const Maxwordshift = Maxwordbit + 1
Config Porta = Output
Config Portd = Output
'===== [ LCD ] =========================
Wport Alias Portc
Dirport Alias Ddrc
Rport Alias Pinc
Rst Alias Porta.4
Lcdcs Alias Porta.5
E Alias Porta.6
Rw Alias Porta.7
A0 Alias Portd.7
Config Rst = Output
Config Lcdcs = Output
Config E = Output
Config Rw = Output
Config A0 = Output
'rest of bootloader
Goto _reset 'Start new program
End
[/code:1:15d955b6f4]
The troubleshooting began when I used the ADC in the Main Program. The following sample will demonstrate the problem. The ADC will always return 0 (zero).
[code:1:15d955b6f4]
'=============================================
' Config ADC test PORTA
'=============================================
$regfile = "m644pdef.dat"
$crystal = 8000000 'internal
$baud = 9600
$hwstack = 128
$swstack = 128
$framesize = 128
'==========================================
'Bootloader Config MEGA644P
'==========================================
$loadersize = $1000
Const Bootloader_start = $7800
' Bootloader Hex $LOADERSIZE
' 8000 none 10000
' 7E00 FC00 $400
' 7C00 F800 $800
' 7800 F000 $1000
' 7000 E000 $2000
'============================================
'Config ADC
'============================================
Config Adc = Single , Prescaler = Auto , Reference = Avcc
Start Adc
Const Adc10bit_volt = 5.0 / 1023
Dim Wadc As Word
Config Single = Scientific , Digits = 1
'============================================
'Scratchpad
'============================================
Dim S As Single , Ss As String * 8
'============================================
' Main
'============================================
Do
Wadc = Getadc(0)
S = Wadc * Adc10bit_volt
Ss = Str(s)
Print Wadc ; " " ; Ss
Wait 2
Loop
End 'end program
[/code:1:15d955b6f4]
I found out that the CONFIG PORTA=Output in the Bootloader affected the ADC function in the main program. It does not appear to be the case that GOTO _Reset actually resets the port configuration.
Only after I removed the CONFIG PORTA line did the ADC work properly in the Main Program. Is there a good explanation? I thought the CONFIG ADC should set the port correctly?
Thanks for any help.
[PS: Similarly, any CONFIG PORTA.x = Output in the main program will not allow the ADC on that pin to function.][/code]
[b:15d955b6f4][color=red:15d955b6f4](BASCOM-AVR version : 2.0.7.6 )[/b:15d955b6f4][/color:15d955b6f4]
↧