Dumken
Member
Have been working on this code for days now. I got stock wen it was time to use tmr0 to do the countdown. Can anyone help me on how to do the countdown using timer zero interrupt once the 'X' key is pressed.
HERE IS THE CODE
Mod Edit!! Use code tags to keep original formatting.
HERE IS THE CODE
C:
unsigned char pattern[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x67};
void mult();
void keycheck();
unsigned char m,no,k,j=7,l;
unsigned int key,First,second,third,fourth,y,counter;
sbit LCD_RS at RC4_bit;
sbit LCD_EN at RC5_bit;
sbit LCD_D4 at RC0_bit;
sbit LCD_D5 at RC1_bit;
sbit LCD_D6 at RC2_bit;
sbit LCD_D7 at RC3_bit;
sbit LCD_RS_Direction at TRISC4_bit;
sbit LCD_EN_Direction at TRISC5_bit;
sbit LCD_D4_Direction at TRISC0_bit;
sbit LCD_D5_Direction at TRISC1_bit;
sbit LCD_D6_Direction at TRISC2_bit;
sbit LCD_D7_Direction at TRISC3_bit;
char txt1[] = "PRESS E TO ENTER";
char txt2[] = " TIME ";
char txt3[] = "DIGITAL ";
char txt4[] = " TIMER ";
char i; // Loop variable
void interrupt()
{
counter++;
if(counter==1953){
if(RD0_Bit==1){
fourth--;
}
else { }
}
counter=0;
T0IF_bit=0;
TMR0=0;
}
void Move_Delay() { // Function used for text moving
Delay_ms(1000); // You can change the moving speed here
}
void Lcd_move(){
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
Lcd_Out(1,6,txt3); // Write text in first row
Lcd_Out(2,6,txt4); // Write text in second row
Delay_ms(500);
Lcd_Cmd(_LCD_CLEAR); // Clear display
while(RD3_Bit==0){
for(i=0; i<18; i++) { // Move text to the right 4 times
Lcd_Cmd(_LCD_SHIFT_RIGHT);
}
Lcd_Out(1,1,txt1); // Write text in first row
Lcd_Out(2,1,txt2); // Write text in second row
Delay_ms(200);
for(i=0; i<18; i++) { // Move text to the right 4 times
Lcd_Cmd(_LCD_SHIFT_LEFT);
}
delay_ms(500);
}
}
void keycheck()
{
no++; // is to know if first,second,....fourth and "enter" key is pressed
if(no==1){
key+=(1000*k);
++;
} //means that the first digit is pressed
if(no==2){
key+=(100*k);
j=j+2;
} //means that the second digit is pressed
if(no==3){
key+=(10*k);
j++;
if(k>5){
Lcd_Cmd(_LCD_CLEAR);
lcd_out(2,3,"wrong Entry");
}
} //means that the third digit is pressed
if(no==4){
key+=k;
j++;
} //means that the last digit is pressed
if(no==5 && y==1){ //will only execute when y=1 made active by the "enter+key"
//no=0; //to re-initialise the digit counter
First=key/1000;
second=(key/100)%10;
third=(key/10)%10;
fourth=(key%10);
lcd_chr(2,7,48+First);
lcd_chr(2,8,48+second);
lcd_chr(2,10,48+third);
lcd_chr(2,11,48+fourth);
key=0;
no=0;
m=0;
y=0;
}
}
void mult()
{
int n;
for(n=0;n<4;n++)
{
PORTB=pattern[First];
RA0_bit=0;
delay_ms(2);
PORTB=0X00;
PORTA=0xff;
PORTB=pattern[second];
RA1_bit=0;
delay_ms(2);
PORTB=0X00;
PORTA=0xff;
PORTB=pattern[third];
RA2_bit=0;
delay_ms(2);
PORTB=0X00;
PORTA=0xff;
PORTB=pattern[fourth];
RA3_bit=0;
delay_ms(2);
PORTB=0X00;
PORTA=0xff;
}
}
void main()
{
TRISB = 0x00;
TRISD = 0x0F;
TRISA = 0xF0;
TRISC = 0;
PORTA = 0x00;
PORTC = 0xFF;
TRISC = 0xff;
ADCON1=0X06;
OPTION_REG=0X80;
INTCON=0XA0;
TMR0=0;
PORTB=0X3F;
PORTD=0xF0;
Lcd_Init();
Lcd_move();
do
{
RD4_bit=1;
mult();
// delay_ms(20);
if(RD0_bit==1 && m<4)
{
k=7;
Lcd_chr(2,j,k+48);
m++;
keycheck();
}
if(RD1_bit==1 && m<4)
{
k=4;
Lcd_chr(2,j,k+48);
m++;
keycheck();
}
if(RD2_bit==1 && m<4)
{
k=1;
Lcd_chr(2,j,k+48);
m++;
keycheck();
}
if(RD3_bit==1)
{
Lcd_Cmd(_LCD_CLEAR);
PORTB=0X00;
lcd_out(1,4,"ENTER TIME");
lcd_out(2,7,"__:__");
keycheck();
key=0;
no=0;
m=0;
y=0;
j=7;
} //column 1
portd=0x00;
RD5_bit=1;
mult(); //serving as the keypad delay and also counting
// delay_ms(20);
if(RD0_bit==1 && m<4)
{
k=8;
Lcd_chr(2,j,k+48);
m++;
keycheck();
}
if(RD1_bit==1 && m<4)
{
k=5;
Lcd_chr(2,j,k+48);
m++;
keycheck();
}
if(RD3_bit==1 && m<4)
{
k=0;
Lcd_chr(2,j,k+48);
m++;
keycheck();
}
if(RD2_bit==1 && m<4)
{
k=2;
Lcd_chr(2,j,k+48);
m++;
keycheck();
}
portd=0x00;
RD6_bit=1;
mult();
// delay_ms(20);
if(RD0_bit==1 && m<4)
{
k=9;
Lcd_chr(2,j,k+48);
m++;
keycheck();
}
if(RD1_bit==1 && m<4)
{
k=6;
Lcd_chr(2,j,k+48);
m++;
keycheck();
}
if(RD2_bit==1 && m<4)
{
k=3;
Lcd_chr(2,j,k+48);
m++;
keycheck();
}
if(RD3_bit==1 && m>3)
{
y=1;
keycheck();
}
portd=0x00;
// RD7_bit=1;
/*mult();
if(RD0_Bit==1 && m>3)
{
RD0_Bit=1;
}*/
}
while(1);
}
Mod Edit!! Use code tags to keep original formatting.
Attachments
Last edited by a moderator: