Quantcast
Channel: MCS Electronics Forum
Viewing all articles
Browse latest Browse all 20563

BASCOM-AVR : RS232 between 2 AVR's : NEWTOPIC

$
0
0
Hello everybody, I'm trying to set up rs232 communication between two atmega168's. Eventually I'm looking to send single numbers from the master to the slave, without checking whether they are received. for the transmitter i've written the following code: I planned to test several datatypes once at a time (word, string, integer, byte) [code:1:9081fbc45d]$regfile = "m168def.dat" $crystal = 16000000 $baud = 600 Config Pinc.2 = Input Config Pinc.5 = Output Config Pinc.4 = Output Knop Alias Pinc.2 Een Alias Pinc.5 Twee Alias Pinc.4 Set Knop Dim Wordwaarde As Word Dim Stringwaarde As String * 10 Dim Intwaarde As Integer Dim Bytewaarde As Byte Dim Waarde1 As String * 2 Dim Waarde2 As String * 2 Waarde1 = "25" Waarde2 = "35" Dim I As Byte Dim X As Byte Do For I = 0 To 10 X = I Mod 2 If X = 0 Then 'verloopindicator Set Een Else Reset Een End If 'Incr Wordwaarde 'test printbin 'Printbin Wordwaarde If X = 0 Then 'test print string Print Waarde1 Else Print Waarde2 End If ' Intwaarde = I 'test print int ' Print Intwaarde ' Bytewaarde = I 'test print byte ' Print Bytewaarde Waitms 500 Next I Loop End [/code:1:9081fbc45d] For the receiver I've written the following code: [code:1:9081fbc45d] $regfile = "m168def.dat" $crystal = 16000000 $baud = 600 Config Pinc.5 = Output Config Pinc.4 = Output Een Alias Pinc.5 Twee Alias Pinc.4 Dim Wordwaarde As Word Dim Vorigword As Word Dim Stringwaarde As String * 10 Dim Vorigstring As String * 10 Dim Intwaarde As Integer Dim Vorigint As Integer Dim Bytewaarde As Byte Dim Vorigbyte As Byte Dim I As Byte Dim X As Byte Set Twee Cursor Off Locate 1 , 1 : Lcd "ontvanger" Locate 2 , 5 : Lcd "Testtekst " Wait 1 Cls Set Een Do 'Inputbin Wordwaarde 'test inputbin 'If Wordwaarde <> Vorigword Then ' Cls ' Locate 1 , 1 ' Lcd Wordwaarde ' Vorigword = Wordwaarde 'End If Input Stringwaarde 'test string input If Stringwaarde <> Vorigstring Then Cls Locate 1 , 1 Lcd I Vorigstring = Stringwaarde End If 'Input Intwaarde 'test integer input 'If Intwaarde <> Vorigint Then ' Cls ' Locate 1 , 1 ' Lcd Intwaarde ' Vorigint = Intwaarde 'End If 'Input Bytewaarde 'test byte input 'If Bytewaarde <> Vorigbyte Then ' Cls ' Locate 1 , 1 ' Lcd Bytewaarde ' Vorigbyte = Bytewaarde 'End If Loop End [/code:1:9081fbc45d] now what happens are the following things: -when I send and receive a string, everything seems to work fine. Exept the fact that there appears a chineese character at the lcd at location 1,1. After that, the text '25' and '35' are displayed. Does anyone know why I get this strange character and how I can fix this? -when I send a word, an integer or a byte, it works only the first time I send something. So after a reset from the receiver, the lcd shows just one time the correct data and after that it keeps displaying 0. Why does it send the firs value without trouble and after that only zero? I'm using 16 MHz crystals with 18 pF capacitors and hooked the tx from the transmitter directly to the rx from the receiver. thanks in advance for the help. Erik :) [b:9081fbc45d][color=red:9081fbc45d](BASCOM-AVR version : 2.0.7.6 )[/b:9081fbc45d][/color:9081fbc45d]

Viewing all articles
Browse latest Browse all 20563

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>