nitaibrata
Newbie
hello am new to microcontroller ,i will be glad if my error could be pointed out please.am writing a code so that real time clock can be displayed but the problem is it doesn´t increment and even so i have to set the time which i think is not ideal if it is rtc.here is my code:
Code:
#include "config.c"
#include "def_pinos.h"
#include <stdio.h>
unsigned int hora, min, seg;
unsigned int check;
//a period = (65535 - 50000) = 3CAF (0.05 s/pulse) */
/* 0.05 x 20 = 1 s/pulse */
void delay_ms(unsigned int tempo){
for (;tempo;tempo--){
TR0 = 0;
TF0 = 0;
TL0 = 0xAF;
TH0 = 0x3C;
TR0 = 1;
while(TF0 == 0);
}
}
void set_time (char Shora, char Smin, char Sseg)
{
hora = Shora;
min = Smin;
seg = Sseg;
}
void print_time ()
{
char h1, h2, m1, m2, s1, s2;
h1 = hora/10 + '0';
h2 = hora%10 + '0';
m1 = min/10 + '0';
m2 = min%10 + '0';
s1 = seg/10 + '0';
s2 = seg%10 + '0';
putchar (h1);
putchar (h2);
putchar (':');
putchar (m1);
putchar (m2);
putchar (':');
putchar (s1);
putchar (s2);
}
void time_inc(void)
{
check++;
if(check==1000)
{
check=0;
seg++;
if(seg>59)
{
seg=0;
min++;
if(min>59)
{
min=0;
hora++;
if (hora==24)
{
hora=0;
}
}
}
}
}
void incrementaTempo () __interrupt 5 //Interrupção a cada 1s
{
seg++;
if (seg<1)
return;
seg = 0;
time_inc();
}
void main () {
Init_Device();
SFRPAGE = LEGACY_PAGE;
TCON=0x00;
TMOD=0x01;
IE=0x83;
TL0 = 0x00;
TH0 = 0xB7;
TR1 = 1;
EA=1;
ET0=1;
set_time (01,02,00);
print_time ();
time_inc();
delay_ms(1000);
}
void putchar (char c) {
SBUF0=c;
while(TI0==0);
TI0=0;
}
void int_serial(void) __interrupt 4{
unsigned char c;
while(!RI0); // Wait until character received completely
c=SBUF0; // Read the character from buffer reg
RI0=0;
}
Last edited by a moderator: