[bascom] OSCCAL byte and tweeking serial communications


From "ian dobson" <i.dobson@planet-ian.com>
Date Fri, 6 May 2005 06:48:52 +0200

Hi All,
 
I've been asked by a friend to quickly bang something together (MEGA8, Serial connection, digital outputs, LCD display) and the board is working as expected, apart from a small problem with the serial/UART.
 
The communication must run at 115200 baud the other end only support this. After playing about for a while I came across this code :-
 
$regfile = "m8def.dat"
'$baud = 19200
$baud = 115200
$crystal = 8000000                                          'setup crystal for ians board
 
Dim J As Byte , X As Byte , S As String * 10 , Y As Byte
Dim Saveoscal As Byte
 
'---------configuration LCD----------------------------------------
 
Config Lcdpin = Pin , Db4 = Portb.7 , Db5 = Portd.7 , _
        Db6 = Portb.6 , Db7 = Portb.0 , E = Portd.6 , _
        Rs = Portd.5                                        'configure lcd screen
Config Lcd = 20 * 2                                         'configure display
 
Saveoscal = Osccal
Do
Cursor Off
Osccal = Osccal - 40
Cls
Lcd "Starting " ; Hex(saveoscal)
Wait 2
For J = 0 To 80
    Osccal = Osccal + 1
    S = Hex(osccal)
    Print "OSCCAL " ; S ; " " ; Osccal
    Locate 2 , 1
    Lcd "OSCCAL " ; S
    Wait 1
Next
Osccal = Saveoscal
Cls
Lcd "Finished"
Loop
End
 
When I run it when connected to a PC I see the output when the value of OSCCAL is between 143 and 163. I've selected 153 for the actual program and it appears to work as expected using the internal RC oscillator. Using an external crystal is not an option (no pins free).
 
Am I going to have problems with this in the future? For example when the temperature changes?
I know that the timing for waitms etc is abit off but thats not a problem for me:)
 
Regards
Ian Dobson
 
Home of the Atmel based UDP mobile web cam http://www.planet-ian.com
All mails scanned with av-filter.pl (F-Prot / perl)