View previous topic :: View next topic |
Author |
Message |
krolikbest
Joined: 02 Jan 2017 Posts: 112
|
Posted: Sun Jan 08, 2017 9:25 pm Post subject: ATMega8 i2cslave display and button |
|
|
Hello,
recently I've made one of my ATmega8 as a slave (I2C).Master is RaspberryPi. I can discover its address so far But now I would like to implement some additional operations like button and lcd display. So there is my code:
<code>
$regfile= "m8def.dat"
$crystal=8000000
config PinB.1=input
Config Lcdpin = Pin , Db4 = PortD.4 ,Db5 = PortD.5 , Db6 = PortD.6 , Db7 = PortD.7 ,E = PortD.0 , Rs = PortD.1
Config Lcd = 16 * 2
Config Twislave = &H20,Btr = 1,Bitrate = 100000,Gencall = 1
$baud = 19200
$hwstack = 32
$swstack = 10
$framesize = 40
Enable Interrupts
Do
if pinB.1=1 then
Locate 1,1
LCD "* "
end if
if pinB.1=0 then
Locate 1,1
LCD "OK"
end if
Loop
'End
Twi_stop_rstart_received:
Print "Master sent stop or repeated start"
Return
Twi_addressed_goread:
Print "We were addressed and master will send data"
Return
Twi_addressed_gowrite:
Print "We were addressed and master will read data"
Return
Twi_gotdata:
Print "received : " ; Twi
Return
Twi_master_needs_byte:
Print "Master needs byte : " ; Twi_btr
Twi = 65 ' twi must be filled with a value
Return
Twi_master_need_nomore_byte:
Print "Master does not need anymore bytes"
Return
</code>
But after pressing button connected to the PinB.1 nothing happens..
If I remove I2C staff it works obviously : after pressing button on the display I see 'OK' or '*'.
What is wrong?
I use Bascom-AVR 2.0.7.6, new library i2cslave, ATMega8-16PU
Martin
(BASCOM-AVR version : 2.0.7.6 , Latest : 2.0.7.8 ) |
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5905 Location: Holland
|
Posted: Mon Jan 09, 2017 2:09 pm Post subject: |
|
|
A few remarks :
- please use the code tags when posting code.
- this code:
Code: | if pinB.1=1 then
Locate 1,1
LCD "* "
end if
if pinB.1=0 then
Locate 1,1
LCD "OK"
end if |
can be written as :
Code: | Locate 1,1
if pinB.1=1 then
LCD "* "
else
LCD "OK"
end if |
- you use portd.1 for the LCD , but you also use PRINT. This will disable the UART pins. SO i suggest to remove the PRINT statements. _________________ Mark |
|
Back to top |
|
|
krolikbest
Joined: 02 Jan 2017 Posts: 112
|
Posted: Mon Jan 09, 2017 7:01 pm Post subject: |
|
|
Thank you for answer.
Of course, You are right, so i did as suggested but unsuccessful. I remarked print even removed, but nothing has changed.
But under simulator the whole program works, at least display is changing depending on button state.
-----------
OK, done!
It was really good hint with UART. I had to change PinD.0 (RxD) as well and then it works.
<SOLVED> |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You cannot download files in this forum
|
|