hic , các bác giúp em với , em viết RTC dung dalas ma sao no ko interupt được.Em sử dung ngắt UIE , và kết nối IRQ với INT1(ngắt ngoài 1) của 89s . mà sao code ko chay vậy. em đoán là nó kô interuppt được
#include "REG52.h"
#include "ABSACC.h"
//define some variable for RTC
#define RTC P2
#define RTC_RegA 0x000A
#define RTC_RegB 0x000B
#define RTC_RegC 0x000C
#define RTC_RegD 0x000D
#define RTC_RegSecond 0x0000
#define RTC_RegMinute 0x0002
#define RTC_RegHour 0x0004
#define RTC_RegDayofweek 0x0006
#define RTC_RegDayofmonth 0x0007
#define RTC_RegMonth 0x0008
#define RTC_RegYear 0x0009
sbit INT = P3^3;
//declare function
void SetRTC(void);
//main function
void main()
{
//set INT1
INT=1; //cong nhap
IE=0x84;//cho phep ngat ngoai 1
IT1=1;//ngat canh xuong
P2=0x0F;
SetRTC;
while(1)
{ ;
//P2=PBYTE[0];
}
}
//===========chuong trinh phuc vu ngat========================
//ngat ngoai 1
void RTC_READY(void) interrupt 2
{
unsigned char kt;
EX1=0;//cam ngat
P2=PBYTE[0]; //doc giay ve va xuat ra P2
kt=PBYTE[RTC_RegC];//xoa thanh ghi C
EX1=1;//cho phep ngat lai
}
//==========set RTC========================
void SetRTC(void)
{
unsigned char t;
// cac bit trong thnah ghi B
// SET PIE AIE UIE SQWE DM 24/12 DSE
PBYTE[RTC_RegB]= 0x12;//
//thanh ghi A
//UIP DV2 DV1 DV0 RS3 RS2 RS1 RS0 = 10100000
//cap nhat lai cho RTC
PBYTE[RTC_RegSecond]=0; //cap nhat du lieu
PBYTE[RTC_RegMinute]=0;
PBYTE[RTC_RegHour]=0 ;
//ket thuc cap nhat
PBYTE[RTC_RegA]= 0x20; //DV2 DV1 DV0 =010 OSC on
PBYTE[RTC_RegB]=0x12; //UIE=1 enable Interupt ended upate
//DM=0 data BCD mode, 24/12=1 24h
//set=0 automatic update data
t=PBYTE[RTC_RegC];//xoa regC
}
#include "ABSACC.h"
//define some variable for RTC
#define RTC P2
#define RTC_RegA 0x000A
#define RTC_RegB 0x000B
#define RTC_RegC 0x000C
#define RTC_RegD 0x000D
#define RTC_RegSecond 0x0000
#define RTC_RegMinute 0x0002
#define RTC_RegHour 0x0004
#define RTC_RegDayofweek 0x0006
#define RTC_RegDayofmonth 0x0007
#define RTC_RegMonth 0x0008
#define RTC_RegYear 0x0009
sbit INT = P3^3;
//declare function
void SetRTC(void);
//main function
void main()
{
//set INT1
INT=1; //cong nhap
IE=0x84;//cho phep ngat ngoai 1
IT1=1;//ngat canh xuong
P2=0x0F;
SetRTC;
while(1)
{ ;
//P2=PBYTE[0];
}
}
//===========chuong trinh phuc vu ngat========================
//ngat ngoai 1
void RTC_READY(void) interrupt 2
{
unsigned char kt;
EX1=0;//cam ngat
P2=PBYTE[0]; //doc giay ve va xuat ra P2
kt=PBYTE[RTC_RegC];//xoa thanh ghi C
EX1=1;//cho phep ngat lai
}
//==========set RTC========================
void SetRTC(void)
{
unsigned char t;
// cac bit trong thnah ghi B
// SET PIE AIE UIE SQWE DM 24/12 DSE
PBYTE[RTC_RegB]= 0x12;//
//thanh ghi A
//UIP DV2 DV1 DV0 RS3 RS2 RS1 RS0 = 10100000
//cap nhat lai cho RTC
PBYTE[RTC_RegSecond]=0; //cap nhat du lieu
PBYTE[RTC_RegMinute]=0;
PBYTE[RTC_RegHour]=0 ;
//ket thuc cap nhat
PBYTE[RTC_RegA]= 0x20; //DV2 DV1 DV0 =010 OSC on
PBYTE[RTC_RegB]=0x12; //UIE=1 enable Interupt ended upate
//DM=0 data BCD mode, 24/12=1 24h
//set=0 automatic update data
t=PBYTE[RTC_RegC];//xoa regC
}
Comment