Problem with reading port

General discussion on mikroPascal for AVR.
Post Reply
Author
Message
Erik-Odinsvej
Posts: 20
Joined: 21 Jan 2008 21:37

Problem with reading port

#1 Post by Erik-Odinsvej » 21 Mar 2008 15:26

I am new to mikroElektronika's compiler - (but not new to pascal)

Maybe I do wrong but I can''t get it to work, when I addresses port to be outout, then all works fine, but not when I wont to check port's for input !

arcording to the manual, I can use the following to check for a input:

if portB.3 then .... - this will not work no matter if I have 0v or 5v on that port !? -
I have found that I can use : if buttom(portB, 3, 100, 1) then ... insted.

I cannot read a 8bit port like this : var:=portC; !

I initials the port like this:

Procedure init; // 0 = input, 1 = output
Begin
DDRA:= %11111111; // bit 0-3 data, 4 clk, 5 rul, 6 rul reset, 7 led
DDRB:= %00011111; // bit 0 run again, 1 play 2 release 3,4 tone
DDRC:= %11000000; // bit 0-5 resultat, 6 tone3, 7 tone4
PORTC:= %00111111; // enable pullups on signal
DDRD:= %00111010; // bit 0+1 new game, 1+2 next game, 4 n,...
PORTD:= %11000101; // enable pullups on signal
End;

(I use a mege644)

can someone come with a clue on what's wrong ?

Best reg. Erik Nielsen, Denmark.

JohannesH
Posts: 68
Joined: 23 Apr 2007 07:51

#2 Post by JohannesH » 21 Mar 2008 20:49

Hi Eric!

Each of the AVR ports has 3 registers associated.

e.g. for PORTB:
Register DDRB - Data Direction Register
Register PORTB - Port B Output Register
Register PINB - Port B Input Register

So, your code "if portB.3 then ..." is wrong, it has to be:
if PINB.3 then ...

If a port is set for input, then the PORTx register has a special function. When writing to PORTx while it is set for input you enable or disable the pullup resistor depending on the value you write to PORTx.

Everything clear now?
Take the time and have a look at the Atmel datasheet of your device. There you will find all this and much more.

Regards from Austria
Johannes

Erik-Odinsvej
Posts: 20
Joined: 21 Jan 2008 21:37

Problem with reading port

#3 Post by Erik-Odinsvej » 23 Mar 2008 14:24

Hi Johannes

Thank you for you reply - this was helpfull !

I know about port and pin for out/input from others compilers,
But in the doc. from mikroElektrinika it state :

"// if RB0 is set, set the 28th bit of myvar:
If PORTB.0 = 1 then myvar.27 := 1;"

- I understand now that it was a bug - it shout been: if PINB.0....

Thanks again
reg. Erik Nielsen[/list]

Post Reply

Return to “mikroPascal for AVR General”