Simple BASIC microcontroller programming question

Do you have a question? Post it now! No Registration Necessary

Translate This Thread From English to

Threaded View


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





Re: Simple BASIC microcontroller programming question



Quoted text here. Click to load it

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

replace
  R = Portb
with
  R = Pinb

HTH

Alan

Quoted text here. Click to load it

--
Sell your surplus electronic components at
http://ozcomponents.com
We've slightly trimmed the long signature. Click to see the full one.
Re: Simple BASIC microcontroller programming question


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





Re: Simple BASIC microcontroller programming question



Quoted text here. Click to load it
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
http://www.mcselec.com /
or directly via
http://www.mcselec.com/index2.php?option=com_forum&Itemid59 %
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
http://ozcomponents.com
We've slightly trimmed the long signature. Click to see the full one.
Re: Simple BASIC microcontroller programming question


Thank you Alan.



Site Timeline