ps_arunkumar
Member level 1

Hi all,
I am trying to write a simple C program to display the no. of times the switch is pressed in the lcd i.e.,when a switch is pressed, the variable gets update and i am displaying it on the lcd. When i do that, it counts upto 9 and from 10 to 15, it displays as symbols and then displays from 20 to 29 and 30 to 35 as symbols .....I dont how to convert the variable so that i properly display from 0 to ....
kindly help me.
thanks,
Arun
//my program
#include<at89x52.h>
#include<lcd.h>
#include<serial.h>
#include<stdio.h>
sbit switch_pin=P1^0;
#define switch_not_pressed(bit) 0
#define switch_pressed (bit) 1
void display_countupdate(unsigned char count)
{
unsigned char temp;
temp=(count);
printf("%d\n", temp);
LCD_clear();
LCD_row1();
send2lcd(temp);
}
bit switch_getinput()
{
unsigned int i;
bit return_value = 0;
if(switch_pin==0)
{
for(i=0;i<=20;i++);
if(switch_pin==0)
{
while(switch_pin==0);
return_value=switch_pressed;
}
}
return return_value;
}
void main(void)
{
unsigned char switch_presses = 0;
switch_pin=0;
PowerOn();
InitSerial();
while(1)
{
if(switch_getinput()==switch_pressed)
{
switch_presses++;
}
display_countupdate(switch_presses);
}
}
I am trying to write a simple C program to display the no. of times the switch is pressed in the lcd i.e.,when a switch is pressed, the variable gets update and i am displaying it on the lcd. When i do that, it counts upto 9 and from 10 to 15, it displays as symbols and then displays from 20 to 29 and 30 to 35 as symbols .....I dont how to convert the variable so that i properly display from 0 to ....
kindly help me.
thanks,
Arun
//my program
#include<at89x52.h>
#include<lcd.h>
#include<serial.h>
#include<stdio.h>
sbit switch_pin=P1^0;
#define switch_not_pressed(bit) 0
#define switch_pressed (bit) 1
void display_countupdate(unsigned char count)
{
unsigned char temp;
temp=(count);
printf("%d\n", temp);
LCD_clear();
LCD_row1();
send2lcd(temp);
}
bit switch_getinput()
{
unsigned int i;
bit return_value = 0;
if(switch_pin==0)
{
for(i=0;i<=20;i++);
if(switch_pin==0)
{
while(switch_pin==0);
return_value=switch_pressed;
}
}
return return_value;
}
void main(void)
{
unsigned char switch_presses = 0;
switch_pin=0;
PowerOn();
InitSerial();
while(1)
{
if(switch_getinput()==switch_pressed)
{
switch_presses++;
}
display_countupdate(switch_presses);
}
}