atmega 8 and PIN -input problem

General discussion on mikroPascal PRO for AVR.
Post Reply
Author
Message
hh
Posts: 8
Joined: 05 Jan 2009 16:24

atmega 8 and PIN -input problem

#1 Post by hh » 05 Jan 2009 16:40

hi
i try to do a "hardware" debouncing ic from atmega8 to use with my other projects. Basicly i want to detect when button is pressed then start to count some time and if button is still down start a new count or if button is up nop.

here is my code

[code]
program nappi;

var l0,l1,l2,l3,l4,l5,l6,l7:byte;
luku0,luku1,luku2,luku3,luku4,luku5:byte; //button count
n0:bit;
n1:bit;
n2:bit;
n3:bit;
n4:bit;
n5:bit;
n6:bit;
n7:bit;
txt : array[4] of char;


// LCD module connections
var LCD_RS : sbit at PORTD.B2;
var LCD_EN : sbit at PORTD.B3;
var LCD_D4 : sbit at PORTD.B4;
var LCD_D5 : sbit at PORTD.B5;
var LCD_D6 : sbit at PORTD.B6;
var LCD_D7 : sbit at PORTD.B7;

var LCD_RS_Direction : sbit at DDRD.B2;
var LCD_EN_Direction : sbit at DDRD.B3;
var LCD_D4_Direction : sbit at DDRD.B4;
var LCD_D5_Direction : sbit at DDRD.B5;
var LCD_D6_Direction : sbit at DDRD.B6;
var LCD_D7_Direction : sbit at DDRD.B7;
// End LCD module connections

procedure ylivuoto; org $009;
begin
if n0=1 then inc(l0);
if l0>100 then n0:=0;

if n1=1 then inc(l1);
if l1>100 then n1:=0;

if n2=1 then inc(l2);
if l2>100 then n2:=0;

if n3=1 then inc(l3);
if l3>100 then n3:=0;

if n4=1 then inc(l4);
if l4>100 then n4:=0;

if n5=1 then inc(l5);
if l5>100 then n5:=0;
end;

begin
asm cli end;
DDrb :=%11;
portb:=%00;
ddrc :=%00000000;
portc:=%11111111;

TCCR0:=00000011;
TIMSK:=1;

Lcd_Init();
Lcd_Cmd(LCD_CLEAR); // Clear display
Lcd_Cmd(LCD_CURSOR_OFF); // Cursor off


luku0:=0;
luku1:=0;
luku2:=0;
luku3:=0;
luku4:=0;
luku5:=0;
n0:=0;
n1:=0;
n2:=0;
n3:=0;
n4:=0;
n5:=0;
asm sei end;
while true do
begin
if n0=0 then if pinc.0=0 then
begin
inc(luku0);
n0:=1;
l0:=0;
end;
if n1=0 then if pinc.1=0 then
begin
inc(luku1);
n1:=1;
l1:=0;
end;
if n2=0 then if pinc.2=0 then
begin
inc(luku2);
n2:=1;
l2:=0;
end;
if n3=0 then if pinc.3=0 then
begin
inc(luku3);
n3:=1;
l3:=0;
end;
if n4=0 then if pinc.4=0 then
begin
inc(luku4);
n4:=1;
l4:=0;
end;
if n5=0 then if pinc.5=0 then
begin
inc(luku5);
n5:=1;
l5:=0;
end;

bytetostr(luku0,txt);
LCD_Out(1,1,txt);
bytetostr(luku1,txt);
LCD_Out(1,5,txt);
bytetostr(luku2,txt);
LCD_Out(1,9,txt);
bytetostr(luku3,txt);
LCD_Out(1,13,txt);
bytetostr(luku4,txt);
LCD_Out(2,1,txt);
bytetostr(luku5,txt);
LCD_Out(2,5,txt);
portb.1:= n1;
portb.0:= n0;
end;
end.

[/code]


it work otherwise but i get strange behavior when i press last button 6 or 16 or 26... times. It also increase some other buttons counter. When i tried first only with two button still same effect?

atmega 8, pro 1.25 (1.26) compiler(demo) and easyavr5a
my english is very bad - sorry

hh
Posts: 8
Joined: 05 Jan 2009 16:24

#2 Post by hh » 06 Jan 2009 21:57

sorry, i have forget glcd on the development board, when i remowe it everything work like it should.

Post Reply

Return to “mikroPascal PRO for AVR General”