2024-07-08
한어Русский языкEnglishFrançaisIndonesianSanskrit日本語DeutschPortuguêsΕλληνικάespañolItalianoSuomalainenLatina
This experiment aims to design and implement a perpetual calendar system based on LCD12864 display of STC89C52 microcontroller, and integrate temperature sensor to realize temperature monitoring function. The system has hourly time and alarm functions, and prompts through buzzer. This design can not only realize basic clock and temperature display, but also has certain alarm functions, which is suitable for scenes such as home or office.
The circuit is mainly composed of a single-chip microcomputer, an LCD display, a temperature sensor and a buzzer. The LCD12864 display is connected to the single-chip microcomputer through a parallel interface, the DS18B20 temperature sensor is connected to the single-chip microcomputer through a single-line interface, and the buzzer is controlled by the I/O port of the single-chip microcomputer.
After the system is powered on, it is initialized first, including LCD display initialization, clock initialization, interrupt initialization, etc. The initialization code is as follows:
void main( void )
{
uchar clock_time[6] = { 0X00, 0X59, 0X23, 0X09, 0X04, 0X11 }; /* 定义时间变量 秒 分 时 日 月 年 */
uchar alarm_time[2] = { 10, 06 }; /* 闹钟设置 alarm_time[0]: 分钟 alarm_time[1] :小时 */
uchar temperature[2]; /* 定义温度变量 temperature[0] 低8位 temperature[1] 高8位 */
Lcd_Initial(); /* LCD初始化 */
Clock_Fresh( clock_time ); /* 刷新时间 */
Clock_Initial( clock_time ); /* 时钟初始化 */
/* 中断初始化 */
EA = 1; /* 开总中断 */
ET0 = 1; /* Timer0 开中断 */
ET2 = 1; /* Timer2 开中断 */
TMOD = 0x01; /* Timer0 工作方式 1 */
RCAP2H = 0x3c;
RCAP2L = 0xb0; /* Timer2 延时 50 ms */
}
The system continuously refreshes the time in the main loop and displays it on the LCD. At the same time, the temperature value is read by the DS18B20 sensor and displayed on the LCD.
while ( 1 )
{
Clock_Fresh( clock_time ); /* 时间刷新 */
Lcd_Clock( clock_time ); /* 时间显示 */
Sensor_Fresh( temperature ); /* 温度更新 */
Lcd_Temperture( temperature ); /* 温度显示 */
/* 整点报时 */
if ( (*clock_time == 0x59)