Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

ATMega8 i2cslave display and button

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    www.mcselec.com Forum Index -> BASCOM-AVR Unsupported versions
View previous topic :: View next topic  
Author Message
krolikbest

Bascom Member



Joined: 02 Jan 2017
Posts: 69

poland.gif
PostPosted: Sun Jan 08, 2017 9:25 pm    Post subject: ATMega8 i2cslave display and button Reply with quote

Hello,

recently I've made one of my ATmega8 as a slave (I2C).Master is RaspberryPi. I can discover its address so far Smile 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
View user's profile
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5061
Location: Holland

blank.gif
PostPosted: Mon Jan 09, 2017 2:09 pm    Post subject: Reply with quote

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
View user's profile Visit poster's website
krolikbest

Bascom Member



Joined: 02 Jan 2017
Posts: 69

poland.gif
PostPosted: Mon Jan 09, 2017 7:01 pm    Post subject: Reply with quote

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
View user's profile
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    www.mcselec.com Forum Index -> BASCOM-AVR Unsupported versions All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
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