Simple BASIC microcontroller programming question

Apr 21, 2006 1 Replies

I would like to input 10 bit from port B pin 0, 1, 2, 3 and output it to port D pin 2, 3, 4, 5, however, my code seem doesn't work. Could you guy please give me some idea and point out the mistake.



Bascom AVR complier, Atmel AT90S8535.



The code is shown as below



$regfile = "8535DEF.dat" $crystal = 8000000


Config Portb = Input Config Portd = Output



Dim R As Word , W As Byte



Do



Ddrb = &B11110000 'set pin 0,1,2,3 as input R = Portb



Ddrd = &B00111100 'set pin 2,3,4,5 as input Portd = R Loop End


[snip]

I would rewrite your loop, Do Ddrb = &B11110000 'set pin 0,1,2,3 as input R = Portb Ddrd = &B00111100 'set pin 2,3,4,5 as input Portd = R Loop as Ddrb = &B11110000 'set pin 0,1,2,3 as input Ddrd = &B00111100 'set pin 2,3,4,5 as input Do Portd = Portb * 4 Loop

You need to shift or rotate the B value 2 bits left. Also you should mask the B value to 4 bits (AND it with &B1111). I'm not familiar with Bascom BASIC so don't know how to do that, and don't know if any part of your program is correct. I imagine it has a whole bunch of errors. Note, post questions like this in the comp.arch.embedded newsgroup instead of sci.electronics.design.

-jiw

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required