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 #include <pic.h> //#include <htc.h> #define RS RB0 #define RW RB1 #define E RB2 void picinit(void); void lcdinit(void); void senddata(char); void command(char); void delay(int); void interrupt ISR(); int sec=0,min=0,hr=0,c,d,e,f,g,h,i=0; void main() { GIE=1; // Global interrupt enable TMR0IE=1; TMR0=0x00; TMR0IF=0; picinit(); lcdinit(); OPTION_REG=0b00000111; while(1) { command(0x80); //star position at 1st row nd 1st column c=hr%10; hr=hr/10; d=hr%10; e=min%10; min=min/10; f=min%10; g=sec%10; sec=sec/10; h=sec%10; senddata(0x30+d); senddata(0x30+c); senddata(0x3a); senddata(0x30+f); senddata(0x30+e); senddata(0x3a); senddata(0x30+h); senddata(0x30+g); //senddata(0x36); } } void interrupt ISR() { if(TMR0IE==1 && TMR0IF==1) { TMR0IF=0; i++; //display(); if(i==72) { sec++; if(sec==60) { min++; sec=0; if(min==60) { hr++; min=0; } } } } } void picinit() { TRISB=0x00;//B port defined as output PORTB=0x00; TRISD=0x00;//D port definrd as output PORTD=0x00; } void lcdinit() { command(0x38);//set function command(0x01);//clear display command(0x0e);//display on cursor blinking //command(0x06); } void command(char comm) { PORTD=comm; RS=0; //register select RW=0;//read or write E=1; //enable data line delay(1000); E=0; //disable data line delay(1000); } void senddata(char data) { PORTD=data; RS=1; RW=0; E=1; delay(1000); E=0; delay(1000); } void delay(int d) { int i; for(i=0;i<=d;i++); }
hi my digital clock program compiled without error , but didnt get the output .
is anything i leave it?..
void command(char comm)
{
PORTD=comm;
RS=0;
RW=0;
__delay_us(60);
E=1;
asm("nop");
E=0;
__delay_ms(2);
}
void senddata(char data)
{
PORTD=data;
RS=1;
RW=0;
__delay_us(60);
E=1;
asm("nop");
E=0;
__delay_us(10);
}
Give some more details like - whether the LCD lights up or not, If black boxes are appearing or not, or if the display is off.
hi i think problem was in ISR only i connected a led to blink on every second increment it seems in low output state only ..If the problem is not with LCD,
then it will be better to include an LED to toggle on each second increment so that you can confirm your ISR is working properly...
void interrupt ISR()
{
if(TMR0IE==1 && TMR0IF==1)
{
TMR0IF=0;
i++;
if(i==72)
{
sec++;
display();
RB4=1;
delay(100000000);
RB4=0;
if(sec==60)
{
min++;
sec=0;
if(min==60)
{
hr++;
min=0;
}
}
}
}
}
void interrupt ISR()
{
if(TMR0IE==1 && TMR0IF==1)
{
TMR0IF=0;
i++;
if(i==72)
{
[B][COLOR="#FF0000"]i=0; //Clear "i", so that it starts counting from 0 again[/COLOR][/B]
sec++;
display();
RB4=1;
delay(100000000);
RB4=0;
if(sec==60)
{
min++;
sec=0;
if(min==60)
{
hr++;
min=0;
}
}
}
}
}
ya my program is here . i cleared i variable but it didnt solve the problem . the display function part are some mathematical to send ascii value to the displayComment out the display() line as you'd done previously, as I don't see a display() routine (you probably have on).
One thing you haven't done here, (which might be the problem) is that, you didn't clear "i" once it got to 72. I think, that's your problem. Since you declared it as int, it keeps on counting until it overflows and then comes to 72 and then, you get another second interrupt, which has now become a lot more than one second.
#include <pic.h>
//#include <htc.h>
#define RS RB0
#define RW RB1
#define E RB2
void picinit(void);
void lcdinit(void);
void senddata(char);
void command(char);
void delay(int);
void interrupt ISR();
void display(void);
int sec=0,min=0,hr=0,c,d,e,f,g,h,i=0;
void main()
{
GIE=1; // Global interrupt enable
TMR0IE=1;
TMR0=0x00;
TMR0IF=0;
picinit();
lcdinit();
OPTION_REG=0b00000111;
while(1);
}
void interrupt ISR()
{
if(TMR0IE==1 && TMR0IF==1)
{
TMR0IF=0;
i++;
if(i==72)
{
i=0;
sec++;
display();
if(sec==60)
{
min++;
sec=0;
if(min==60)
{
hr++;
min=0;
}
}
}
}
}
void picinit()
{
TRISB=0x00;//B port defined as output
PORTB=0x00;
TRISD=0x00;//D port definrd as output
PORTD=0x00;
}
void lcdinit()
{
command(0x38);//set function
command(0x01);//clear display
command(0x0e);//display on cursor blinking
//command(0x06);
}
void command(char comm)
{
PORTD=comm;
RS=0; //register select
RW=0;//read or write
E=1; //enable data line
delay(1000);
E=0; //disable data line
delay(1000);
}
void senddata(char data)
{
PORTD=data;
RS=1;
RW=0;
E=1;
delay(1000);
E=0;
delay(1000);
}
void display(void)
{
command(0x80); //star position at 1st row nd 1st column
c=hr%10;
hr=hr/10;
d=hr%10;
e=min%10;
min=min/10;
f=min%10;
g=sec%10;
sec=sec/10;
h=sec%10;
senddata(0x30+d);
senddata(0x30+c);
senddata(0x3a);
senddata(0x30+f);
senddata(0x30+e);
senddata(0x3a);
senddata(0x30+h);
senddata(0x30+g);
//senddata(0x36);
}
void delay(int d)
{
int i;
for(i=0;i<=d;i++);
}
#include <pic.h>
//#include <htc.h>
#define RS RB0
#define RW RB1
#define E RB2
void picinit(void);
void lcdinit(void);
void senddata(char);
void command(char);
void delay(int);
void interrupt ISR();
void display(void);
int sec=0,min=0,hr=0,c,d,e,f,g,h,i=0;
char display_flag;
void main()
{
GIE=1; // Global interrupt enable
TMR0IE=1;
TMR0=0x00;
TMR0IF=0;
picinit();
lcdinit();
OPTION_REG=0b00000111;
while(1) {
while(display_flag == 0);
display_flag = 0;
display();
}
}
void interrupt ISR()
{
if(TMR0IE==1 && TMR0IF==1)
{
TMR0IF=0;
i++;
if(i==72)
{
i=0;
sec++;
display_flag = 1;
//display();
if(sec==60)
{
min++;
sec=0;
if(min==60)
{
hr++;
min=0;
}
}
}
}
}
void picinit()
{
TRISB=0x00;//B port defined as output
PORTB=0x00;
TRISD=0x00;//D port definrd as output
PORTD=0x00;
}
void lcdinit()
{
command(0x38);//set function
command(0x01);//clear display
command(0x0e);//display on cursor blinking
//command(0x06);
}
void command(char comm)
{
PORTD=comm;
RS=0; //register select
RW=0;//read or write
E=1; //enable data line
delay(1000);
E=0; //disable data line
delay(1000);
}
void senddata(char data)
{
PORTD=data;
RS=1;
RW=0;
E=1;
delay(1000);
E=0;
delay(1000);
}
void display(void)
{
command(0x80); //star position at 1st row nd 1st column
c=hr/10;
d=hr%10;
e=min/10;
f=min%10;
g=sec/10;
h=sec%10;
senddata(0x30+d);
senddata(0x30+c);
senddata(0x3a);
senddata(0x30+f);
senddata(0x30+e);
senddata(0x3a);
senddata(0x30+h);
senddata(0x30+g);
//senddata(0x36);
}
void delay(int d)
{
int j;
for(j=0;j<=d;j++);
}
Code:while(1) { while(display_flag == 0); display_flag = 0; display(); } }
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?