Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

switch for display a number 1,2,3 in lcd display

Status
Not open for further replies.

suga

Member level 2
Member level 2
Joined
Jan 23, 2012
Messages
49
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Location
chennai
Activity points
1,596
hi

how to display 1,2,3 by pressing a only one switch.1st I press a switch 1 has to come.for 2 presses 2 has to come.for 3 presses 3 has to come.for display am using Lcd.
 

create a timer and check the number of press events in a particular time...

------------or------------simply
1.detect the button press by high or low level using if condition
2.wait & continiouly check press event like below and display



Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
if (BUTTON1 == PRESSED) 
{
char press = press + 1;  
 
 
for (i=0;i>=10;i++) 
{
delay_ms(100);
press = press + 1;    
};
 
display lcd (press);
 
};





this programme will display number of presses of button .

---------- Post added at 12:29 ---------- Previous post was at 12:27 ----------

you can modify this programme according to your compiler and micro but concept will be the same.
 
Last edited by a moderator:
thank u.please explain timer concept also..

---------- Post added at 08:20 ---------- Previous post was at 08:19 ----------

am using 8051 micro controller,keil compiler
 

you can start and stop any timer by programme in any micro.

1.start a timer when a button is pressed and increment a ---





Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
if (BUTTON1 == PRESSED) 
{ 
 
// always increment this variable when button is pressed
press = press + 1;
    
 
// start timer for 1 seconed --- after one second it will fire its interrupt survice routine 
 
if (g==0) {startimer; g=2;};// now g will be zero only in timer interrupt
 
};
 
 
 
 
 
// Timer 0 overflow interrupt service routine
interrupt [TIM0_OVF] void timer0_ovf_isr(void)
{
// after one second programm will be here and now first display no. of presses of button in one second
diplay LCD (press); 
 
 
// refresh all varaible for next work
g=0;
stop timer; 
 
}





2.fire a timer interrupt in a certain time defined by u .
for example --
 
Last edited by a moderator:
am using keil software.micro controller 8051
 

Code:
#include<reg51.h>
//LCD pins initialization
sbit button=P2^0;
void main()
{
count=0;
while(1)
{
  if (button==0)
{
   count++;
lcd_data(count+48);
while(button==0);
}

}


you add the LCD commands and data functions.


Hope This may help
 
if pressed the switch or button it will give low pulse when it gives count will b incremented and wait till the key is released .
when u released it will wait till the next time key is pressed. if u pressed again the count will b incremented by 1 i.e.2 ..like this it will go on..
You have to display the count value on lcd with adding 48 to it(To make it Ascii)
 

Hi...
This is my program...when I press the button one time 'a' has to display.when I press the same button 2 times 'b' has to display.same button is pressed 3 times 'c' has to display.its like a mobile keys.here am using 4x4 keypad and for display am using lcd.output is not coming



Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
#include<reg51.h>
#define p0 P0
#define p2 P2    
sbit c1=P2^4;
sbit c2=P2^5;
sbit c3=P2^6;
sbit c4=P2^7;
sbit r1=P2^0;
sbit r2=P2^1;
sbit r3=P2^2;
sbit r4=P2^3;
 
sfr c=0x90;
sbit rs=P3^7;
sbit rw=P3^6;
sbit en=P3^5;
unsigned char position=128,i=0;
int check_again[10]={0,0,0,0,0,0,0,0,0,0};
void lcd();
void keypad();
void num_check(int a,int b) ;
 
void lcd_d( char val);
void lcd_in( char val);
 
 
 
void wait(int j)
{
long int i;
for(i=0;i<j;i++);
}
 
void lcd_in(unsigned char val)
{
c=val;
rs= 0;
rw=0;
en=1;
wait(10);
en=0;
return;
}
 
void lcd_d(unsigned char val)
{
lcd_in(0x0f);
wait(10);
c= val;
rs= 1;
rw=0;
en=1;
wait(10);
en=0;
return;
}
 
void num_check(int a,int b)  //Check function
{
int j;
for(j=0;j<10;j++)
{
   if(j!=a)
  {
   check_again[j]=0;
  }
}
if(check_again[a]==3)
check_again[a]=0;
check_again[11]=1;
check_again[12]=1;
}
 
void display(int a,int b) // Display function
{
switch(b)
{
case 1:
{
    switch(a)
        {
             case 1:{
                if(check_again[a]>1)
                i--;
                lcd_in(position+i);
                lcd_d('a');
                wait(5000);
                 // num_check(1 ,check_again[1]);
                break;
                    }
}         }
case 2:
{
     switch(a)
     {
         
            case 1:{
                if(check_again[a]>1)
                i--;
                lcd_in(position+i);
                lcd_d('b');
                 wait(5000);
                // num_check(1 ,check_again[1]);
                break;
                    }
        }
}
case 3:
{
     switch(a)
     {
         
            case 1:{
                if(check_again[a]>1)
                i--;
                lcd_in(position+i);
                lcd_d('c');
                 wait(5000);
                // num_check(1 ,check_again[1]);
                break;
                    }
        }
}
}
}
void keypad()
{
if (c4=0,c2=c3=c1=1,r4==0)
{
p0=0xf0;
display(1);
lcd_in(0x0c);
}
}
void main()
{
p2=0x0f;
lcd();
 
while(1)
{
p0=0xfe;
keypad();
 
 
wait(5000);
//p0=0xfd;
//keypad();
 
 
//wait(5000);
 
//p0=0xfb;
//keypad();
 
//wait(5000);
//p0=0xf7;
//keypad();
 
//wait(5000);
 
}
}
void lcd()
{
lcd_in(0x38);
wait(250);
lcd_in(0x0e);
wait(250);
lcd_in(0x01);
wait(250);
lcd_in(0x06);
wait(250);
lcd_in(0x86);
wait(250);
lcd_in(0x80);
wait(250);
}



---------- Post added at 08:34 ---------- Previous post was at 08:08 ----------

Now I understood ur coding.why we have to add 48
 
Last edited by a moderator:
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top