|
|
View previous topic :: View next topic |
Author |
Message |
Abidi
Joined: 12 May 2014 Posts: 6
|
keypad |
Posted: Thu May 22, 2014 9:27 am |
|
|
Hi, I'm working in a project in which i used a keypad to enter value.
After entering this value, i want to return to execute the rest of my program, but the problem is that the execution still blocked on the function of keypad :(
I will appreciate your help.
Code: |
#include <main.h>
#define LCD_ENABLE_PIN PIN_D0
#define LCD_RS_PIN PIN_D2
#define LCD_RW_PIN PIN_D1
#define LCD_DATA4 PIN_D6
#define LCD_DATA5 PIN_D5
#define LCD_DATA6 PIN_D4
#define LCD_DATA7 PIN_D3
#define buzzer PIN_D7
#use fast_io(a)
#include <lcd.c>
#include <flex_kbd.c>
char k;
unsigned long int lecture;
float v, Ifuite,Imax;
int j=60;
void keypad()
{
lcd_init();
kbd_init();
lcd_gotoxy(1,1);
printf(lcd_putc,"Entrer les");
lcd_gotoxy(1,2);
printf(lcd_putc,"parametres");
delay_ms (1500) ;
lcd_init();
printf(lcd_putc,"Imax=%c",k);
while (TRUE)
{
k=kbd_getc();
if(k!=0)
lcd_putc(k);
if(k=='#')
lcd_putc("\fTension\n");
if (k=='*')
lcd_putc("\fTemps\n");
}
}
void test()
{
if ( Ifuite < Imax)
{
output_low(pin_c0);
lcd_init();
printf(lcd_putc,"test OK \r");
output_high(pin_c1);
delay_ms(1500);
output_low(pin_c1);
}
else if ( Ifuite >= Imax)
{
output_low(pin_c0);
lcd_init();
printf(lcd_putc,"test NOT OK \r");
//output_high(pin_d7);
output_high(pin_c2);
delay_ms(1500);
output_low(pin_c2);
}
void main()
{
lcd_init();
printf(lcd_putc,"Bienvenue \r");
delay_ms (1500) ;
lcd_init();
printf(lcd_putc,"sagemcom \r");
delay_ms (1500) ;
keypad();
lcd_init();
printf(lcd_putc,"start test \n");
delay_ms (1500);
printf(lcd_putc,"test en cours \r");
output_high(pin_C0);
delay_ms (1500);
setup_adc_ports(AN0);
setup_adc(ADC_CLOCK_INTERNAL);
lcd_init();
set_adc_channel(0);
delay_us(20);
while(true)
{
lecture=read_adc();
delay_us(20);
v=lecture*0.0048828125;
delay_us(10);
ifuite=v/1.5;
delay_us(10);
lcd_init();
lcd_gotoxy(1,1);
printf(lcd_putc,"I=%fmA",Ifuite);
lcd_gotoxy(1,2);
printf(lcd_putc,"Ttest=%d",j);
j=j-1;
if(j==0)
{
lcd_init();
test();
}
}
} |
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu May 22, 2014 9:48 am |
|
|
This sample code shows how to poll the keypad every 10 ms in an
interrupt routine. If a key is pressed, it's put into a circular buffer.
Your main code can check 'bkbhit' to see if a character is available
in the keypad buffer. If so, you can get the character with bgetc().
http://www.ccsinfo.com/forum/viewtopic.php?t=42707&start=4
Because this keypad loop doesn't block (it's run by interrupts), you
can do other activities in your main loop. |
|
|
Abidi
Joined: 12 May 2014 Posts: 6
|
keypad |
Posted: Sun May 25, 2014 5:10 am |
|
|
ok thanks and how can i store a value of current entered by keypad, displayed on lcd, because in test i need this value to do the comparison. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|