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.

sir i need help how to reset time in lcd using interrupt(using 89s52 microcontrol)

Status
Not open for further replies.

manoharagn

Newbie level 5
Joined
Nov 20, 2011
Messages
8
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,283
Location
BENGALURU
Activity points
1,333
sir i got output to display time in lcd using 89s52.but i need the help whenever i press the switch in the board the time will start from beginning using external interrupt.
here is the code how to modify the code.

Code:
#include<reg51.h>
#define cont_port P3
#define port P1
#define dataport P2 // Data port for LCD
#define m_sec 10
sbit rs = cont_port^0;
sbit rw = cont_port^1;
sbit en = cont_port^6;
sbit dig_hr1=port^0;
sbit dig_min1=port^1;
sbit start=port^2;
sbit am_pm=port^3;
int hr ,hr1=0;
int min,min1=0;
int sec,sec1=0,dig_am_pm=0;

void delay(unsigned int msec) // Time delay funtion
{
int i,j ;
for(i=0;i<msec;i++)
for(j=0;j<1275;j++);
}


void lcd_cmd(unsigned char item) // Function to send command on LCD
{
dataport = item;
rs= 0;
rw=0;
en=1;
delay(1);
en=0;
return;
}

void lcd_data(unsigned char item) // Function to send data on LCD
{
dataport = item;
rs= 1;
rw=0;
en=1;
delay(1);
en=0;
return;
}

void lcd_data_string(unsigned char *str) // Function to send string on LCD
{
int i=0;
while(str[i]!='\0')
{
lcd_data(str[i]);
i++;
delay(1);
}
return;
}

lcd_data_int(int time_val) // Function to send number on LCD
{
int int_amt;
int_amt=time_val/10;
lcd_data(int_amt+48);
int_amt=time_val;
lcd_data(int_amt+48);
}

void lcd(unsigned char str1[10]) // Function to initialize LCD
{
lcd_cmd(0x38); //2 LINE, 5X7 MATRIX
lcd_cmd(0x0e); //DISPLAY ON, CURSOR BLINKING
delay(m_sec);
lcd_data_string(str1);
}

void set_hr1() // Function to set hour
{
hr1++;
if(hr1>11)
hr1=0;
lcd_cmd(0xc3);
lcd_data_int(hr1);
lcd_data(':');
}

void set_min1() // Function to set minute
{
min1++;
if(min1>59)
min1=0;
lcd_cmd(0xc6);
lcd_data_int(min1);
}

void main()
{
int k;
start=1;
dig_hr1=1;
dig_min1=1;
lcd_cmd(0x01);
lcd_cmd(0x83);
lcd("SET TIMING");
lcd_cmd(0xc3);
lcd_data_int(hr1);
lcd_data(':');
lcd_data_int(min1);
while(start==0)
{
delay(10);
if(dig_hr1==0)
set_hr1();
if(dig_min1==0)
set_min1();
}

if(am_pm==0)
{
lcd_cmd(0xc8);
lcd_data_string("am");
dig_am_pm=0;
}

if(am_pm==1)
{
lcd_cmd(0xc8);
lcd_data_string("pm");
dig_am_pm=1;
}
delay(200);
lcd_cmd(0x01);
while(1)
{
for(k=0;k<2;k++)
{
for(hr=hr1;hr<12;hr++)
{
for(min=min1;min<60;min++)
{
for(sec=0;sec<60;sec++)
{
lcd_cmd(0x82);
delay(1);
lcd_data_int(hr);
lcd_data(':');
lcd_data_int(min);
lcd_data(':');
lcd_data_int(sec);
if(dig_am_pm==0)
{
lcd("am");
}
else
{
lcd("pm");
}
lcd_data_string(" ");
delay(100);
}
}
min1=0;
}
if(dig_am_pm==0)
dig_am_pm=1;
else
dig_am_pm=0;
hr1=0;
}
}
}
 
Last edited by a moderator:

simply make out a function and let it be called by your interrupt handler(for external interrupt) and in that function, assign your variables that are counting i.e. am,pm,hr,min,sec....etc.. to value zero..
 
  • Like
Reactions: manoharagn

    manoharagn

    Points: 2
    Helpful Answer Positive Rating
    V

    Points: 2
    Helpful Answer Positive Rating
sir i tried my level...i put the code like this
void timer0() interrupt 1
{
min1=0;
hr1=0;
sec1=0;
}
and i initialized IE=0x84; for external hardware interrupt INT1 in the main program but didn't got output.
 

look, you can check if your external interrupt is working or not,,simply by putting a led to some output pin of controller,, and in the interrupt function blink it..so that it will help you in debugging..
you may get to know that your function is getting is called atleast..
if it is not getting called then think for the reasons because of which it is happening...check the schematic if you have properly soldered the wires to external interrupt 1 not 0..i.e pin13(as i remember)..(as ie=84h)...
 
thanks for your answer sir. Finally got output at the pin INT0(P3.2) don't know why at the pin p3.3 not got output.
anyway thank u very much.
 
Last edited:

arey no need for thanks.. its all your efforts...
 

..... sir now implementing whenever i press switch(ground),the counter increment to 1.(sir i think external h/w interrupts are low level interrupt so its working when i connected to GND instead of switch).
for counting i changed the code like this


void timer0()interrupt 0

{

hr1=0;hr=0;
min=0;min1=0;
sec=0;sec1=0;
if(cont_port^2==0)
{

count=count+1;
lcd_cmd(0xC8);
lcd_data_string("count=");



}
}


is this correct ? i not got output.......whether i hv to use counter here?
 

first of all, you must be reading out the interrupt pins structure and their working bro,,,
please do read Mazidi for 8051..It is clearly written out there that these external interrupts are active low!!
these two interrupts are normally high,, you have to supply logic low to work with them.....

now, tell me two things..
what you want to do with the counter increment?
what is function lcd_cmd(0xC8); doing? are you sending 0c8 to the lcd as cmd.. so as to move the cursor to c8 position..somewhere center of the second line???(for 16*2 lcd)
 
sir i need the counter to count how many times i reset the time .i used lcd_cmd(0xc8)(i think that "conut=" ll take 6 or 7 positions in lcd after that my counting value ll be shown) to display counter value at that position but i don't know how to get that value to that position.......sir i am the beginner so i learning each and every line of the program and concepts.

lcd_cmd(0xc0) this command is fine to display starting from 2 line.
 
Last edited:

its ok,

count=count+1;
lcd_cmd(0xC8);
lcd_data_string("count=");
from these lines, it is appearing that you are incrementing counter everytime the function is called..
then, you are moving the lcd cursor to the c8 position(almost to the center of screen in the second line).
then, you are make the string "count=" to appear on the lcd..
but then you are doing nothing i.e. you are not making the count value to appear on the screen..show the count value on the lcd too..

n what is cont_port^2??I dont see it in the program above..
n as soon as you press the switch (external interrupt is called)..then for what purpose you are using if condition again...?
make the counter increment there only..
initiallise all other things to zero.
and call the lcd functions to display the "count value" (also the "count=" string if you want)
 

hai sir got output i modified the code as


void timer0()interrupt 0

{

//lcd_cmd(0x01);//
hr1=0;hr=0;
min=0;min1=0;
sec=0;sec1=0;

count=count++;

lcd_cmd(0xC0);
lcd_data_string("count=:");
value=(count/10);////////////for ascii conversion. it ll count upto 99
lcd_data(value+48);
value=(count%10);
lcd_data(value+48);


}
 

yeah, it worked as i said you are using the if condition for unknown purpose..
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top