Simple BASIC microcontroller programming question

Apr 21, 2006 4 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. Thank you very much



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


If you want to read the input on a port you must use PINx

replace R = Portb with R = Pinb

HTH

Alan

-- Sell your surplus electronic components at

formatting link
Search or browse for that IC, capacitor, crystal or other component you need.

Thank you Alan, I've try to PinB before, but the value seem is not correct.

Correct output can show from 0-9 in 7 segment display, but this one only can only show 0-3.

I knew it is little bit hard to understand my Situation.

Thanks anyway

When you read the port with R = PinB you read all 8 bits/pins. Whether they are inputs or outputs doesn't matter they all get read into R.

When you then write Portd = R you then write out bits 0, 1, 6 and 7 from port B plus pins 2, 3, 4 and 5 will be either high or low depending on what you have connected externally.

It would be more useful to know what you have connected on ports B and D and what you are trying to do.

Also you may want to consider going to the Bascom forum either via

formatting link
or directly via
formatting link
there you can post huge chunks of code without anyone getting upset and there is lots of help.

HTH

Alan

-- Sell your surplus electronic components at

formatting link
Search or browse for that IC, capacitor, crystal or other component you need.

Join the Discussion

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

Didn't find your answer?

Ask the community — no account required