BÁO CÁO BÀI TẬP LỚN NHÚNG I.Bài 1.Tên đề tài : thiết kế hệ thống lò ấp trứng, điều khiển công suất quạt đèn sưởi theo giá trị nhiệt độ môi trường, hiển thị nhiệt độ lên hình LCD 2.Sơ đồ tổng quan hệ thống 3.Lưu đồ thuật toán 4.Thiết bị phần cứng 4.1.Pic16f877a 4.2.Cảm biến nhiệt độ LM35 4.3.Quạt tản nhiệt 4.4.Đèn sưởi 4.5.LCD 16x2 4.6.Nút nhấn on/off 4.7.Nút dừng khẩn cấp 4.8.Rơ le điện từ 4.9.Đèn báo hệ thống 5.Code chương trình /* * File: newmain.c * Author: DUNG Created on January 14, 2022, 10:36 AM */ * #include #include #include #include // CONFIG #pragma config FOSC = HS #pragma config WDTE = OFF disabled) #pragma config PWRTE = OFF disabled) #pragma config BOREN = OFF disabled) #pragma config LVP = OFF // Low-Voltage (Single-Supply) In-Circuit Serial Programming Enable bit (RB3 is digital I/O, HV on MCLR must be used for programming) #pragma config CPD = OFF // Data EEPROM Memory Code Protection bit (Data EEPROM code protection off) #pragma config WRT = OFF // Flash Program Memory Write Enable bits (Write protection off; all program memory may be written to by EECON control) #pragma config CP = OFF #define _XTAL_FREQ 20000000 #define TMR2PRESCALE long f; /*****/ #define RS RB0 #define EN RB1 #define D4 RB2 #define D5 RB3 #define D6 RB4 #define D7 RB5 void Lcd_Port(char a) { if(a & 1) D4=1; else D4=0; if(a & 2) D5=1; else D5=0; if(a & 4) D6=1; else D6=0; if(a & 8) D7=1; else D7=0; } /****************************/ void Lcd_Cmd(char a) { RS=0;//=>RS=0 Lcd_Port(a); EN=1;//=>E=1 delay_ms(4); EN=0;//=>E=0 } /**************************/ void Lcd_Init() { Lcd_Port(0x00); delay_ms(20); Lcd_Cmd(0x03); delay_ms(5); Lcd_Cmd(0x03); delay_ms(11); Lcd_Cmd(0x03); Lcd_Cmd(0x02); Lcd_Cmd(0x02); Lcd_Cmd(0x08); Lcd_Cmd(0x00); Lcd_Cmd(0x0C); Lcd_Cmd(0x00); Lcd_Cmd(0x06); } /*************************/ void Lcd_Clear() { Lcd_Cmd(0); Lcd_Cmd(1); } /*****************************/ void Lcd_Set_Cursor(char a, char b) { char temp,z,y; if(a == 1) { temp = 0x80 + b - 1; z = temp>>4; y = temp & 0x0F; Lcd_Cmd(z); Lcd_Cmd(y); } else if(a == 2) { temp = 0xC0 + b - 1; z = temp>>4; y = temp & 0x0F; Lcd_Cmd(z); Lcd_Cmd(y); } } /**************************/ void Lcd_Write_Char(char a) { char temp,y; temp = a&0x0F; y = a&0xF0; RS=1;//=>RS=1 Lcd_Port(y>>4); //Data transfer EN=1; delay_us(40); EN=0; Lcd_Port(temp); EN=1; delay_us(40); EN=0; } /****************************/ void Lcd_Write_String(char *a) { int i; for(i=0;a[i]!='\0';i++) Lcd_Write_Char(a[i]); } /*******************************/ void Lcd_Shift_Right() { Lcd_Cmd(0x01); Lcd_Cmd(0x0C); } /********************************/ void Lcd_Shift_Left() { Lcd_Cmd(0x01); Lcd_Cmd(0x08); } Lcd_Set_Cursor(2,1); sprintf(b,"nhiet do=%d",a); Lcd_Write_String(b); delay_ms(1000); } } if(aRS=0 Lcd_Port(a); EN=1;//=>E=1 delay_ms(4); EN=0;//=>E=0 } /**************************/ void Lcd_Init() { Lcd_Port(0x00); delay_ms(20); Lcd_Cmd(0x03); delay_ms(5); Lcd_Cmd(0x03); delay_ms(11); Lcd_Cmd(0x03); Lcd_Cmd(0x02); Lcd_Cmd(0x02); Lcd_Cmd(0x08); Lcd_Cmd(0x00); Lcd_Cmd(0x0C); Lcd_Cmd(0x00); Lcd_Cmd(0x06); } /*************************/ void Lcd_Clear() { Lcd_Cmd(0); Lcd_Cmd(1); } /*****************************/ void Lcd_Set_Cursor(char a, char b) { char temp,z,y; if(a == 1) { temp = 0x80 + b - 1; z = temp>>4; y = temp & 0x0F; Lcd_Cmd(z); Lcd_Cmd(y); } else if(a == 2) { temp = 0xC0 + b - 1; z = temp>>4; y = temp & 0x0F; Lcd_Cmd(z); Lcd_Cmd(y); } } /**************************/ void Lcd_Write_Char(char a) { char temp,y; temp = a&0x0F; y = a&0xF0; RS=1;//=>RS=1 Lcd_Port(y>>4); //Data transfer EN=1; delay_us(40); EN=0; Lcd_Port(temp); EN=1; delay_us(40); EN=0; } /****************************/ void Lcd_Write_String(char *a) { int i; for(i=0;a[i]!='\0';i++) Lcd_Write_Char(a[i]); } /*******************************/ void Lcd_Shift_Right() { Lcd_Cmd(0x01); Lcd_Cmd(0x0C); } /********************************/ void Lcd_Shift_Left() { Lcd_Cmd(0x01); Lcd_Cmd(0x08); } void main(void) { int dem =0; char b[20]; TRISD6 = 1; TRISD7 = 1; TRISB = 0x00; Lcd_Init(); TRISC1 = ; TRISC4 = ; while(1) { Lcd_Set_Cursor(1,1); Lcd_Write_String("bai xe"); if(!RD6) { delay_ms(1000); if(!RD6) { dem=dem+1; RC1 = 1; //DC ON delay_ms(500); //3 Second Delay RC1 = 0; //DC OFF if(dem>100) dem=100; } } if(!RD7) { delay_ms(1000); if(!RD7) { dem=dem-1; RC4 = 1; //DC ON delay_ms(500); //3 Second Delay RC4 = 0; //DC OFF if(dem