e post bài này xin sự trợ giúp và chỉ giáo của mọi người
tình hình là e làm mạch đồng hồ báo thức hiển thị thời gian thực dùng vdk atmega8 hiển thị lên glcd 128x64
mà code e nạp vào chạy mô phỏng trên proteus được mà khi ra mạch thực lại k được
mọi người có thể sửa giúp e để hiển thị lên con Glcd 128x64 được k ạ
/************************************************** ***
This program was produced by the
CodeWizardAVR V2.05.6
Automatic Program Generator
© Copyright 1998-2012 Pavel Haiduc, HP InfoTech s.r.l.
http://www.hpinfotech.com
Project : khang
Version : 13
Date : 3/23/2020
Author : Cracked By PerTic@n (Evaluation)
V1.0 - SonSivRi.to
Company : VTK40
Comments:
Chip type : ATmega8
Program type : Application
AVR Core Clock frequency: 1.000000 MHz
Memory model : Small
External RAM size : 0
Data Stack size : 256
************************************************** ***/
#include <mega8.h>
// I2C Bus functions
#include <i2c.h>
// DS1307 Real Time Clock functions
#include <ds1307.h>
// Alphanumeric LCD functions
#include <alcd.h>
// Declare your global variables here
#include <delay.h>
#define MODE PIND.0
#define UP PIND.1
#define DOWN PIND.2
#define OFF PIND.3
#define MODE2 PIND.5
#define BT PIND.6
#define LED PIND.7
bit AP; // che do 24h(1), 12h(0)
bit sb; // sb=1 phim duoc nhan sb=0 phim khong duoc nhan
bit alarm_en;
bit alarm_en1;
bit alarm_en2;
bit alarm_en3;
bit alarm_en4;
bit led_en;
unsigned int h_led1=0,m_led1=0,h_led=0,m_led=0,h_set=0, m_set=0, h_set1=0,m_set1=0, h_set2=0, m_set2=0, h_set3=0,m_set3=0,h_set4=0,m_set4=0,m_ring4=1, m_ring3=1,m_ring1=1,m_ring2=1,m_ring=1;
unsigned char hour,min,sec,day,date,month,year,mode,h,No_date,mo de2;
//Chuong trinh con
// Ham hien thi thu(day)
void display_day(unsigned char x){
switch(x){
case 1: lcd_putsf(" 2");
break;
case 2: lcd_putsf(" 3");
break;
case 3: lcd_putsf(" 4");
break;
case 4: lcd_putsf(" 5");
break;
case 5: lcd_putsf(" 6");
break;
case 6: lcd_putsf(" 7");
break;
case 7: lcd_putsf(" 8");
break;
default:
};
}
//Ham doi ngay
void check_conveter_day(void){
if (day==8) day=1;
if (day==0) day=7;
rtc_set_date(day,date,month,year);
}
//Ham doi che do 12h <=> 24h
void check_conveter_hour(void){
// kiem tra che do gio hien tai
if(AP==0){// che do 12h (AP=0)
if(hour>12) h=hour-12;
else h=hour;
}
else h=hour; //che do 24h(AP=1)
}
//Ham hien thi time len LCD
void display_time_lcd(unsigned char x, unsigned char y){
lcd_gotoxy(x,y);
lcd_putchar(48+h/10); //hang chuc
lcd_putchar(48+h%10); // hang don vi
lcd_putsf(":");
lcd_putchar(48+min/10); //hang chuc
lcd_putchar(48+min%10); // hang don vi
lcd_putsf(":");
lcd_putchar(48+sec/10); //hang chuc
lcd_putchar(48+sec%10); // hang don vi
}
//Ham hien thi date len LCD
void display_date_lcd(unsigned char x, unsigned char y){
lcd_gotoxy(x,y);
lcd_putchar(48+date/10); //hang chuc
lcd_putchar(48+date%10); // hang don vi
lcd_putsf("/");
lcd_putchar(48+month/10); //hang chuc
lcd_putchar(48+month%10); // hang don vi
lcd_putsf("/");
lcd_putchar(48+year/10); //hang chuc
lcd_putchar(48+year%10); // hang don vi
display_day(day); //hien thi thu
}
//Ham hien thi o che do hen gio
void display_hengio_lcd(unsigned char x, unsigned char y){
lcd_gotoxy(x,y);
lcd_putchar(48+h_set/10); //hang chuc
lcd_putchar(48+h_set%10); // hang don vi
lcd_putsf(":");
lcd_putchar(48+m_set/10); //hang chuc
lcd_putchar(48+m_set%10); // hang don vi
}
void display_hengio_lcd1(unsigned char x, unsigned char y){
lcd_gotoxy(x,y);
lcd_putchar(48+h_set1/10); //hang chuc
lcd_putchar(48+h_set1%10); // hang don vi
lcd_putsf(":");
lcd_putchar(48+m_set1/10); //hang chuc
lcd_putchar(48+m_set1%10); // hang don vi
}
void display_hengio_lcd2(unsigned char x, unsigned char y){
lcd_gotoxy(x,y);
lcd_putchar(48+h_set2/10); //hang chuc
lcd_putchar(48+h_set2%10); // hang don vi
lcd_putsf(":");
lcd_putchar(48+m_set2/10); //hang chuc
lcd_putchar(48+m_set2%10); // hang don vi
}
void display_hengio_lcd3(unsigned char x, unsigned char y){
lcd_gotoxy(x,y);
lcd_putchar(48+h_set3/10); //hang chuc
lcd_putchar(48+h_set3%10); // hang don vi
lcd_putsf(":");
lcd_putchar(48+m_set3/10); //hang chuc
lcd_putchar(48+m_set3%10); // hang don vi
}
void display_hengio_lcd4(unsigned char x, unsigned char y){
lcd_gotoxy(x,y);
lcd_putchar(48+h_set4/10); //hang chuc
lcd_putchar(48+h_set4%10); // hang don vi
lcd_putsf(":");
lcd_putchar(48+m_set4/10); //hang chuc
lcd_putchar(48+m_set4%10); // hang don vi
}
void display_hengio_lcd7(unsigned char x, unsigned char y){
lcd_gotoxy(x,y);
lcd_putchar(48+h_led/10); //hang chuc
lcd_putchar(48+h_led%10); // hang don vi
lcd_putsf(":");
lcd_putchar(48+m_led/10); //hang chuc
lcd_putchar(48+m_led%10); // hang don vi
}
void display_hengio_lcd8(unsigned char x, unsigned char y){
lcd_gotoxy(x,y);
lcd_putchar(48+h_led1/10); //hang chuc
lcd_putchar(48+h_led1%10); // hang don vi
lcd_putsf(":");
lcd_putchar(48+m_led1/10); //hang chuc
lcd_putchar(48+m_led1%10); // hang don vi
}
//Ham hien thi tren LCD
void display_lcd(void) { //hien thi Time len LCD
lcd_gotoxy(0,0);
lcd_putsf("Time: "); //hien thi thoi gian
display_time_lcd(6,0);
// hien thi date len LCD
lcd_gotoxy(0,1);
lcd_putsf("Date: ");
display_date_lcd(6,1);
}
void bitbit()
{
{
PORTD.6=0;
delay_ms(50);
PORTD.6=1;
delay_ms(50);
}
PORTD.6=1;
}
//Chuong trinh kiem tra phim nhan
void status_button(void){
if(MODE&&UP&&DOWN&&OFF&&sb&&MODE2){
sb=0; //kiem tr phim da nha chua
}
}
//Ham kiem tra so ngay trong thang
void Ndate_in_month(void){
if(month==2){
if(year%4==0) No_date=29;
else No_date=28;
}
else if(month==1||month==3||month==5||month==7||month== 8||month==10||month==12) No_date=31;
else No_date=30;
}
//Ham cai dat thoi gian va bao thuc
void set_alarm_time(void){
status_button();
// chuyen doi che do 12h<==>24h
if ((OFF==0)&&(sb==0)){
AP=~AP; // doi che do gio hien thi
sb=1; //bao co phim nhan
}
status_button();
// chon che do nguoi dung
if(MODE==0&&sb==0){
//chon che do
if(mode==27){
mode=1;
}
else{
mode++;
}
sb=1;
}
//che do mode=0 hien thong tin
if(mode==0){
lcd_gotoxy(0,0);
lcd_putsf("DO AN");
lcd_gotoxy(0,1);
lcd_putsf(" VTK40 ");
delay_ms(2000); // tu chuyen sang che do binh thuong
mode++;
}
//che do mode=1 hien thi binh thuong
if(mode==1){
lcd_clear();
display_lcd();
}
//che do mode=2 chinh gio
if(mode==2){
lcd_clear();
// che do chinh gio
lcd_gotoxy(0,0);
lcd_putsf("SET GIO: ");
lcd_putsf(" ");
display_time_lcd(5,1);
lcd_putsf(" ");
status_button();
if(UP==0&&sb==0){
// phim UP duoc nhan
if(hour==23) hour=0;
else hour++;
rtc_set_time(hour,min,sec); //Dat lai gio cho DS1307
sb=1;
}
status_button();
if(DOWN==0&&sb==0){
if(hour==0) hour=23;
else hour--;
rtc_set_time(hour,min,sec);
sb=1;
}
}
if(mode==3){
// che do chinh phut
lcd_clear();
lcd_gotoxy(0,0);
lcd_putsf("SET PHUT: ");
lcd_putsf(" ");
display_time_lcd(5,1);
lcd_putsf(" ");
status_button();
if(UP==0&&sb==0){
// phim UP duoc nhan
if(min==59) min=0;
else min++;
rtc_set_time(hour,min,sec); //Dat lai phut cho DS1307
sb=1;
}
status_button();
if(DOWN==0&&sb==0){
if(min==0) min=59;
else min--;
rtc_set_time(hour,min,sec);
sb=1;
}
}
//che do mode=5 chinh thu va ngay
if(mode==4){
lcd_clear();
lcd_gotoxy(0,0);
lcd_putsf("SET NGAY: ");
lcd_putsf(" ");
display_date_lcd(5,1);
lcd_putsf(" ");
Ndate_in_month();
status_button();
if(UP==0&&sb==0){
// phim UP duoc nhan
if(day==7) day=1;
else day++;
// xac dinh ngay(date) khi chinh thu
if(date==No_date){
if(month==12){ //chuyen sang nam moi
date=1;
month=1;
year++;
}
else{
date=1;month++; // het thang thi sang thang moi
}
}
else date++;
rtc_set_date(day,date,month,year);
sb=1;
}
status_button();
if(DOWN==0&&sb==0){
if(day==1) day=7;
else day--;
if(date==1){
//VD 1/3 chuyen thanh 28(19)/2
if(month==1){
month=12;date=31;year--;
}
else{
month--;
Ndate_in_month();
date=No_date;
}
}
else date--;
rtc_set_date(day,date,month,year);
sb=1;
}
}
//che do mode=6 chinh thang
if(mode==5){
// che do chinh thang
lcd_clear();
lcd_gotoxy(0,0);
lcd_putsf("SET THANG: ");
lcd_putsf(" ");
display_date_lcd(5,1);
lcd_putsf(" ");
Ndate_in_month();
status_button();
if(UP==0&&sb==0){
// phim UP duoc nhan
if(month==12){
month=1;
if(year==99) year=0;
else year++;
}
else month++;
//xac dinh thu(day) khi chinh thang(month)
if((day+No_date%7)>7)
day=day+No_date%7-7;
else day=day+No_date%7;
Ndate_in_month(); // cap nhat so ngay toi da cua thang cua dat lai
if(date>No_date) date=No_date;
//31/3 phai thanh 30/4 khi nhan UP
rtc_set_date(day,date,month,year);
sb=1;
}
status_button();
if(DOWN==0&&sb==0){
if(month==1){
hour=12;
if(year==0) year=99;
else year--;
}
else month--;
Ndate_in_month();
// kiem tra tinh theo so ngay thang truoc de xac dinh thu
if(day<No_date%7) day=day-No_date%7+7;
else day=day-No_date%7;
if(date>No_date) date=No_date;
// VD tu 31/3 phai thanh 29/2 khi an DOWN(month)
rtc_set_date(day,date,month,year);
sb=1;
}
}
//che do mode=7 chinh nam
if(mode==6){
lcd_clear();
// che do chinh name
lcd_gotoxy(0,0);
lcd_putsf("SET NAM: ");
lcd_putsf(" ");
display_date_lcd(5,1);
lcd_putsf(" ");
status_button();
if(UP==0&&sb==0){
// phim UP duoc nhan
if((year%4==0)&&(month==1)&&(date==29))
{
//ngay 29/2 nam nhuan
date=28;
}
// chinh thu(day) khi chuyen nam
if(year%4==0){ //nam nhuan
if((month==1)||((month==2)&&(date<29)))
{
if(day==7) // thu 8
day=2; //thu 3
else day=day+2;
}
else day=day+1; // nam nhuan nhung thu chi tang 1 ngay
}
else day=day+1; // ko phai nam nhuan
// chuyen nam
if(year==99)
year=0;
else year++;
rtc_set_date(day,date,month,year);
sb=1;
}
status_button();
if(DOWN==0&&sb==0){
if(year%4==0){ //nam nhuan
if((month>2)||((month==2)&&(date==29)))
{
if(day==1) // thu 2
day=6; // thu 7
else day-=2;
}
else day-=1; // nam nhuan nhung thu chi lui 1 ngay
}
else day-=1; // khong phai nam nhuan
// chuyen ngay cua thang 2 khi chuyen thu nam nhuan sang nam ko nhuan
if((year%4==0)&&((month==2)&&(date==29)))
{
// ngay 29/2 nam nhuan
date=28;
}
// chinh nam
if(year==0) year=99;
else year--;
rtc_set_date(day,date,month,year);
sb=1;
}
}
// che do mode=8 chinh gio trong che do hen gio
if(mode==7){
lcd_clear();
lcd_gotoxy(0,0);
lcd_clear();
lcd_putsf("BTHUC1: ");
display_hengio_lcd(8,0);
lcd_gotoxy(0,1);
lcd_putsf("GIO: ");
lcd_gotoxy(8,1);
lcd_putchar(h_set/10+48);
lcd_putchar(h_set%10+48);
lcd_putsf(" ");
status_button();
if(UP==0&&sb==0){
if(h_set==23) h_set=0;
else h_set++;
sb=1;
}
status_button();
if(DOWN==0&&sb==0){
if(h_set==0) h_set=23;
else h_set--;
sb=1;
}
}
//che do mode=8 chinh phut trong che do hen gio
if(mode==8){
lcd_clear();
// che do chinh phut
lcd_gotoxy(0,0);
lcd_putsf("BTHUC1: ");
display_hengio_lcd(8,0);
lcd_gotoxy(0,1);
lcd_putsf("PHUT: ");
lcd_gotoxy(8,1);
lcd_putchar(m_set/10+48);
lcd_putchar(m_set%10+48);
lcd_putsf(" ");
status_button();
if(UP==0&&sb==0){
// phim UP duoc nhan
if(m_set==59) m_set=0;
else m_set++;
sb=1;
}
status_button();
if(DOWN==0&&sb==0){
if(m_set==0) m_set=59;
else m_set--;
sb=1;
}
}
if(mode==9){
lcd_clear();
lcd_gotoxy(0,0);
lcd_putsf(" BTHUC1 ");
lcd_gotoxy(0,1);
lcd_putsf("RING: ");
lcd_gotoxy(8,1);
lcd_putchar(m_ring/10+48);
lcd_putchar(m_ring%10+48);
lcd_putsf(" ");
status_button();
if(UP==0&&sb==0){
// phim UP duoc nhan
if(m_ring==59) m_ring=0;
else m_ring++;
sb=1;
}
status_button();
if(DOWN==0&&sb==0){
if(m_ring==0) m_ring=59;
else m_ring--;
sb=1;
}
}
if(mode==10){
lcd_clear();
lcd_gotoxy(0,0);
lcd_putsf("BAO THUC 1 ???");
lcd_gotoxy(0,1);
lcd_putsf(" ");
if(UP==0&&sb==0){
alarm_en=1;
lcd_gotoxy(0,1);
lcd_putsf("ON ");
}
if(DOWN==0&&sb==0)
{
alarm_en=0;
lcd_gotoxy(0,1);
lcd_putsf("OFF");
}
}
if(mode==11){
lcd_clear();
lcd_gotoxy(0,0);
lcd_putsf("BTHUC2: ");
display_hengio_lcd1(8,0);
lcd_gotoxy(0,1);
lcd_putsf("GIO: ");
lcd_gotoxy(8,1);
lcd_putchar(h_set1/10+48);
lcd_putchar(h_set1%10+48);
lcd_putsf(" ");
status_button();
if(UP==0&&sb==0){
if(h_set1==23) h_set1=0;
else h_set1++;
sb=1;
}
status_button();
if(DOWN==0&&sb==0){
if(h_set1==0) h_set1=23;
else h_set1--;
sb=1;
}
}
//che do mode=8 chinh phut trong che do hen gio
if(mode==12){
lcd_clear();
// che do chinh phut
lcd_gotoxy(0,0);
lcd_putsf("BTHUC2: ");
display_hengio_lcd1(8,0);
lcd_gotoxy(0,1);
lcd_putsf("PHUT: ");
lcd_gotoxy(8,1);
lcd_putchar(m_set1/10+48);
lcd_putchar(m_set1%10+48);
lcd_putsf(" ");
status_button();
if(UP==0&&sb==0){
// phim UP duoc nhan
if(m_set1==59) m_set1=0;
else m_set1++;
sb=1;
}
status_button();
if(DOWN==0&&sb==0){
if(m_set1==0) m_set1=59;
else m_set1--;
sb=1;
}
}
if(mode==13){
lcd_clear();
lcd_gotoxy(0,0);
lcd_putsf(" BTHUC2 ");
lcd_gotoxy(0,1);
lcd_putsf("RING: ");
lcd_gotoxy(8,1);
lcd_putchar(m_ring1/10+48);
lcd_putchar(m_ring1%10+48);
lcd_putsf(" ");
status_button();
if(UP==0&&sb==0){
// phim UP duoc nhan
if(m_ring1==59) m_ring1=0;
else m_ring1++;
sb=1;
}
status_button();
if(DOWN==0&&sb==0){
if(m_ring1==0) m_ring1=59;
else m_ring1--;
sb=1;
}
}
if(mode==14){
lcd_clear();
lcd_gotoxy(0,0);
lcd_putsf("BAO THUC 2 ???");
lcd_gotoxy(0,1);
lcd_putsf(" ");
if(UP==0&&sb==0){
alarm_en1=1;
lcd_gotoxy(0,1);
lcd_putsf("ON ");
}
if(DOWN==0&&sb==0)
{
alarm_en1=0;
lcd_gotoxy(0,1);
lcd_putsf("OFF");
}
}
if(mode==15){
lcd_clear();
lcd_gotoxy(0,0);
lcd_putsf("BTHUC3: ");
display_hengio_lcd2(8,0);
lcd_gotoxy(0,1);
lcd_putsf("GIO: ");
lcd_gotoxy(8,1);
lcd_putchar(h_set2/10+48);
lcd_putchar(h_set2%10+48);
lcd_putsf(" ");
status_button();
if(UP==0&&sb==0){
if(h_set2==23) h_set2=0;
else h_set2++;
sb=1;
}
status_button();
if(DOWN==0&&sb==0){
if(h_set2==0) h_set2=23;
else h_set2--;
sb=1;
}
}
//che do mode=8 chinh phut trong che do hen gio
if(mode==16){
lcd_clear();
// che do chinh phut
lcd_gotoxy(0,0);
lcd_putsf("BTHUC3:");
display_hengio_lcd2(8,0);
lcd_gotoxy(0,1);
lcd_putsf("PHUT: ");
lcd_gotoxy(8,1);
lcd_putchar(m_set2/10+48);
lcd_putchar(m_set2%10+48);
lcd_putsf(" ");
status_button();
if(UP==0&&sb==0){
// phim UP duoc nhan
if(m_set2==59) m_set2=0;
else m_set2++;
sb=1;
}
status_button();
if(DOWN==0&&sb==0){
if(m_set2==0) m_set2=59;
else m_set2--;
sb=1;
}
}
if(mode==17){
lcd_clear();
lcd_gotoxy(0,0);
lcd_putsf(" BTHUC3 ");
lcd_gotoxy(0,1);
lcd_putsf("RING: ");
lcd_gotoxy(8,1);
lcd_putchar(m_ring2/10+48);
lcd_putchar(m_ring2%10+48);
lcd_putsf(" ");
status_button();
if(UP==0&&sb==0){
// phim UP duoc nhan
if(m_ring2==59) m_ring2=0;
else m_ring2++;
sb=1;
}
status_button();
if(DOWN==0&&sb==0){
if(m_ring2==0) m_ring2=59;
else m_ring2--;
sb=1;
}
}
if(mode==18){
lcd_clear();
lcd_gotoxy(0,0);
lcd_putsf("BAO THUC 3 ???");
lcd_gotoxy(0,1);
lcd_putsf(" ");
if(UP==0&&sb==0){
alarm_en2=1;
lcd_gotoxy(0,1);
lcd_putsf("ON ");
}
if(DOWN==0&&sb==0)
{
alarm_en2=0;
lcd_gotoxy(0,1);
lcd_putsf("OFF");
}
}
if(mode==19){
lcd_clear();
lcd_gotoxy(0,0);
lcd_putsf("BTHUC4: ");
display_hengio_lcd3(8,0);
lcd_gotoxy(0,1);
lcd_putsf("GIO: ");
lcd_gotoxy(8,1);
lcd_putchar(h_set3/10+48);
lcd_putchar(h_set3%10+48);
lcd_putsf(" ");
status_button();
if(UP==0&&sb==0){
if(h_set3==23) h_set3=0;
else h_set3++;
sb=1;
}
status_button();
if(DOWN==0&&sb==0){
if(h_set3==0) h_set3=23;
else h_set3--;
sb=1;
}
}
//che do mode=8 chinh phut trong che do hen gio
if(mode==20){
lcd_clear();
// che do chinh phut
lcd_gotoxy(0,0);
lcd_putsf("BTHUC4:");
display_hengio_lcd3(8,0);
lcd_gotoxy(0,1);
lcd_putsf("PHUT: ");
lcd_gotoxy(8,1);
lcd_putchar(m_set3/10+48);
lcd_putchar(m_set3%10+48);
lcd_putsf(" ");
status_button();
if(UP==0&&sb==0){
// phim UP duoc nhan
if(m_set3==59) m_set3=0;
else m_set3++;
sb=1;
}
status_button();
if(DOWN==0&&sb==0){
if(m_set3==0) m_set3=59;
else m_set3--;
sb=1;
}
}
if(mode==21){
lcd_clear();
lcd_gotoxy(0,0);
lcd_putsf(" BTHUC4 ");
lcd_gotoxy(0,1);
lcd_putsf("RING: ");
lcd_gotoxy(8,1);
lcd_putchar(m_ring3/10+48);
lcd_putchar(m_ring3%10+48);
lcd_putsf(" ");
status_button();
if(UP==0&&sb==0){
// phim UP duoc nhan
if(m_ring3==59) m_ring3=0;
else m_ring3++;
sb=1;
}
status_button();
if(DOWN==0&&sb==0){
if(m_ring3==0) m_ring3=59;
else m_ring3--;
sb=1;
}
}
if(mode==22){
lcd_clear();
lcd_gotoxy(0,0);
lcd_putsf("BAO THUC 4 ???");
lcd_gotoxy(0,1);
lcd_putsf(" ");
if(UP==0&&sb==0){
alarm_en3=1;
lcd_gotoxy(0,1);
lcd_putsf("ON ");
}
if(DOWN==0&&sb==0)
{
alarm_en3=0;
lcd_gotoxy(0,1);
lcd_putsf("OFF");
}
}
if(mode==23){
lcd_clear();
lcd_gotoxy(0,0);
lcd_putsf("BTHUC5: ");
display_hengio_lcd4(8,0);
lcd_gotoxy(0,1);
lcd_putsf("GIO: ");
lcd_gotoxy(8,1);
lcd_putchar(h_set4/10+48);
lcd_putchar(h_set4%10+48);
lcd_putsf(" ");
status_button();
if(UP==0&&sb==0){
if(h_set4==23) h_set4=0;
else h_set4++;
sb=1;
}
status_button();
if(DOWN==0&&sb==0){
if(h_set4==0) h_set4=23;
else h_set4--;
sb=1;
}
}
//che do mode=8 chinh phut trong che do hen gio
if(mode==24){
lcd_clear();
// che do chinh phut
lcd_gotoxy(0,0);
lcd_putsf("BTHUC5:");
display_hengio_lcd4(8,0);
lcd_gotoxy(0,1);
lcd_putsf("PHUT: ");
lcd_gotoxy(8,1);
lcd_putchar(m_set4/10+48);
lcd_putchar(m_set4%10+48);
lcd_putsf(" ");
status_button();
if(UP==0&&sb==0){
// phim UP duoc nhan
if(m_set4==59) m_set4=0;
else m_set4++;
sb=1;
}
status_button();
if(DOWN==0&&sb==0){
if(m_set4==0) m_set4=59;
else m_set4--;
sb=1;
}
}
if(mode==25){
lcd_clear();
lcd_gotoxy(0,0);
lcd_putsf(" BTHUC5 ");
lcd_gotoxy(0,1);
lcd_putsf("RING: ");
lcd_gotoxy(8,1);
lcd_putchar(m_ring4/10+48);
lcd_putchar(m_ring4%10+48);
lcd_putsf(" ");
status_button();
if(UP==0&&sb==0){
// phim UP duoc nhan
if(m_ring4==59) m_ring4=0;
else m_ring4++;
sb=1;
}
status_button();
if(DOWN==0&&sb==0){
if(m_ring4==0) m_ring4=59;
else m_ring4--;
sb=1;
}
}
if(mode==26){
lcd_clear();
lcd_gotoxy(0,0);
lcd_putsf("BAO THUC 5 ???");
lcd_gotoxy(0,1);
lcd_putsf(" ");
if(UP==0&&sb==0){
alarm_en4=1;
lcd_gotoxy(0,1);
lcd_putsf("ON ");
}
if(DOWN==0&&sb==0)
{
alarm_en4=0;
lcd_gotoxy(0,1);
lcd_putsf("OFF");
}
}
}
void baothuc(){
if(((alarm_en==1)&&(hour==h_set)&&(min==m_set))||( (alarm_en1==1)&&(hour==h_set1)&&(min==m_set1))||(( alarm_en2==1)&&(hour==h_set2)&&(min==m_set2))||((a larm_en3==1)&&(hour==h_set3)&&(min==m_set3))||((al arm_en4==1)&&(hour==h_set4)&&(min==m_set4)))
{
bitbit();
}
if(min==m_ring&&hour==h_set)
{
PORTD.6=0;
}
if(min==m_ring1&&hour==h_set1)
{
PORTD.6=0;
}
if(min==m_ring2&&hour==h_set2)
{
PORTD.6=0;
}
if(min==m_ring3&&hour==h_set3)
{
PORTD.6=0;
}
if(min==m_ring4&&hour==h_set4)
{
PORTD.6=0;
}
status_button();
if(OFF==0&&sb==0){
PORTD.6=0;
alarm_en=0;alarm_en1=0;alarm_en2=0;alarm_en3=0;ala rm_en4=0;
sb=1;
}
}
void set_led_time(void){
if(MODE2==0&&sb==0){
mode=27;
//chon che do
if(mode2==6){
mode2=0;
mode=1;
}
else{
mode2++;
}
sb=1;
}
if(mode2==1){
lcd_clear();
lcd_gotoxy(0,0);
lcd_putsf("LEDON: ");
display_hengio_lcd7(8,0);
lcd_gotoxy(0,1);
lcd_putsf("GIO: ");
lcd_gotoxy(8,1);
lcd_putchar(h_led/10+48);
lcd_putchar(h_led%10+48);
lcd_putsf(" ");
status_button();
if(UP==0&&sb==0){
if(h_led==23) h_led=0;
else h_led++;
sb=1;
}
status_button();
if(DOWN==0&&sb==0){
if(h_led==0) h_led=23;
else h_led--;
sb=1;
}
}
if(mode2==2){
lcd_gotoxy(0,0);
lcd_putsf("LEDON: ");
display_hengio_lcd7(8,0);
lcd_gotoxy(0,1);
lcd_putsf("PHUT: ");
lcd_gotoxy(8,1);
lcd_putchar(m_led/10+48);
lcd_putchar(m_led%10+48);
lcd_putsf(" ");
status_button();
if(UP==0&&sb==0){
if(m_led==59) m_led=0;
else m_led++;
sb=1;
}
status_button();
if(DOWN==0&&sb==0){
if(m_led==0) m_led=59;
else m_led--;
sb=1;
}
}
if(mode2==3){
lcd_gotoxy(0,0);
lcd_putsf("LEDOF: ");
display_hengio_lcd8(8,0);
lcd_gotoxy(0,1);
lcd_putsf("GIO: ");
lcd_gotoxy(8,1);
lcd_putchar(h_led1/10+48);
lcd_putchar(h_led1%10+48);
lcd_putsf(" ");
status_button();
if(UP==0&&sb==0){
if(h_led1==23) h_led1=0;
else h_led1++;
sb=1;
}
status_button();
if(DOWN==0&&sb==0){
if(h_led1==0) h_led1=23;
else h_led1--;
sb=1;
}
}
if(mode2==4){
lcd_gotoxy(0,0);
lcd_putsf("LEDOF: ");
display_hengio_lcd8(8,0);
lcd_gotoxy(0,1);
lcd_putsf("PHUT: ");
lcd_gotoxy(8,1);
lcd_putchar(m_led1/10+48);
lcd_putchar(m_led1%10+48);
lcd_putsf(" ");
status_button();
if(UP==0&&sb==0){
if(m_led1==59) m_led1=0;
else m_led1++;
sb=1;
}
status_button();
if(DOWN==0&&sb==0){
if(m_led1==0) m_led1=59;
else m_led1--;
sb=1;
}
}
if(mode2==5){
lcd_gotoxy(0,0);
lcd_putsf("BAT DEN HAY KO");
lcd_gotoxy(0,1);
lcd_putsf(" ");
if(UP==0&&sb==0){
led_en=1;
PORTD.7=1;
lcd_gotoxy(0,1);
lcd_putsf("ON ");
}
if(DOWN==0&&sb==0)
{
led_en=0;
PORTD.7=0;
lcd_gotoxy(0,1);
lcd_putsf("OFF");
}
}
}
void battatled(){
if((h_led==hour)&&(m_led==min)&&(led_en==1))
{
PORTD.7=1;
}
if((h_led1==hour)&&(m_led1==min))
{
PORTD.7=0;
}
status_button();
if(OFF==0&&sb==0){
led_en=0;
sb=1;
}
}
void main(void)
{
// Input/Output Ports initialization
// Port B initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTB=0x00;
DDRB=0x00;
// Port C initialization
// Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTC=0x00;
DDRC=0x00;
// Port D initialization
// Func7=Out Func6=Out Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=0 State6=0 State5=T State4=T State3=T State2=T State1=T State0=T
PORTD=0x00;
DDRD=0xC0;
// Timer/Counter 0 initialization
// Clock source: System Clock
// Clock value: Timer 0 Stopped
TCCR0=0x00;
TCNT0=0x00;
// Timer/Counter 1 initialization
// Clock source: System Clock
// Clock value: Timer1 Stopped
// Mode: Normal top=0xFFFF
// OC1A output: Discon.
// OC1B output: Discon.
// Noise Canceler: Off
// Input Capture on Falling Edge
// Timer1 Overflow Interrupt: Off
// Input Capture Interrupt: Off
// Compare A Match Interrupt: Off
// Compare B Match Interrupt: Off
TCCR1A=0x00;
TCCR1B=0x00;
TCNT1H=0x00;
TCNT1L=0x00;
ICR1H=0x00;
ICR1L=0x00;
OCR1AH=0x00;
OCR1AL=0x00;
OCR1BH=0x00;
OCR1BL=0x00;
// Timer/Counter 2 initialization
// Clock source: System Clock
// Clock value: Timer2 Stopped
// Mode: Normal top=0xFF
// OC2 output: Disconnected
ASSR=0x00;
TCCR2=0x00;
TCNT2=0x00;
OCR2=0x00;
// External Interrupt(s) initialization
// INT0: Off
// INT1: Off
MCUCR=0x00;
// Timer(s)/Counter(s) Interrupt(s) initialization
TIMSK=0x00;
// USART initialization
// USART disabled
UCSRB=0x00;
// Analog Comparator initialization
// Analog Comparator: Off
// Analog Comparator Input Capture by Timer/Counter 1: Off
ACSR=0x80;
SFIOR=0x00;
// ADC initialization
// ADC disabled
ADCSRA=0x00;
// SPI initialization
// SPI disabled
SPCR=0x00;
// TWI initialization
// TWI disabled
TWCR=0x00;
// I2C Bus initialization
// I2C Port: PORTC
// I2C SDA bit: 1
// I2C SCL bit: 0
// Bit Rate: 100 kHz
// Note: I2C settings are specified in the
// Project|Configure|C Compiler|Libraries|I2C menu.
i2c_init();
// DS1307 Real Time Clock initialization
// Square wave output on pin SQW/OUT: On
// Square wave frequency: 32768Hz
rtc_init(3,1,0);
// Alphanumeric LCD initialization
// Connections are specified in the
// Project|Configure|C Compiler|Libraries|Alphanumeric LCD menu:
// RS - PORTB Bit 0
// RD - PORTB Bit 1
// EN - PORTB Bit 2
// D4 - PORTB Bit 4
// D5 - PORTB Bit 5
// D6 - PORTB Bit 6
// D7 - PORTB Bit 7
// Characters/line: 16
lcd_init(16);
sb=0; //mac dinh la ko co nut bam
while (1)
{
// Place your code here
// Place your code here
rtc_get_time(&hour,&min,&sec);
// doc gio, phut, day tu DS1307
rtc_get_date(&day,&date,&month,&year);
// doc ngay thang nam tu DS1307
check_conveter_day(); //kiem tra va chuyen sang mac dinh
check_conveter_hour();
status_button();
set_alarm_time();
baothuc();
set_led_time();
battatled();
}
}
tình hình là e làm mạch đồng hồ báo thức hiển thị thời gian thực dùng vdk atmega8 hiển thị lên glcd 128x64
mà code e nạp vào chạy mô phỏng trên proteus được mà khi ra mạch thực lại k được
mọi người có thể sửa giúp e để hiển thị lên con Glcd 128x64 được k ạ
/************************************************** ***
This program was produced by the
CodeWizardAVR V2.05.6
Automatic Program Generator
© Copyright 1998-2012 Pavel Haiduc, HP InfoTech s.r.l.
http://www.hpinfotech.com
Project : khang
Version : 13
Date : 3/23/2020
Author : Cracked By PerTic@n (Evaluation)
V1.0 - SonSivRi.to
Company : VTK40
Comments:
Chip type : ATmega8
Program type : Application
AVR Core Clock frequency: 1.000000 MHz
Memory model : Small
External RAM size : 0
Data Stack size : 256
************************************************** ***/
#include <mega8.h>
// I2C Bus functions
#include <i2c.h>
// DS1307 Real Time Clock functions
#include <ds1307.h>
// Alphanumeric LCD functions
#include <alcd.h>
// Declare your global variables here
#include <delay.h>
#define MODE PIND.0
#define UP PIND.1
#define DOWN PIND.2
#define OFF PIND.3
#define MODE2 PIND.5
#define BT PIND.6
#define LED PIND.7
bit AP; // che do 24h(1), 12h(0)
bit sb; // sb=1 phim duoc nhan sb=0 phim khong duoc nhan
bit alarm_en;
bit alarm_en1;
bit alarm_en2;
bit alarm_en3;
bit alarm_en4;
bit led_en;
unsigned int h_led1=0,m_led1=0,h_led=0,m_led=0,h_set=0, m_set=0, h_set1=0,m_set1=0, h_set2=0, m_set2=0, h_set3=0,m_set3=0,h_set4=0,m_set4=0,m_ring4=1, m_ring3=1,m_ring1=1,m_ring2=1,m_ring=1;
unsigned char hour,min,sec,day,date,month,year,mode,h,No_date,mo de2;
//Chuong trinh con
// Ham hien thi thu(day)
void display_day(unsigned char x){
switch(x){
case 1: lcd_putsf(" 2");
break;
case 2: lcd_putsf(" 3");
break;
case 3: lcd_putsf(" 4");
break;
case 4: lcd_putsf(" 5");
break;
case 5: lcd_putsf(" 6");
break;
case 6: lcd_putsf(" 7");
break;
case 7: lcd_putsf(" 8");
break;
default:
};
}
//Ham doi ngay
void check_conveter_day(void){
if (day==8) day=1;
if (day==0) day=7;
rtc_set_date(day,date,month,year);
}
//Ham doi che do 12h <=> 24h
void check_conveter_hour(void){
// kiem tra che do gio hien tai
if(AP==0){// che do 12h (AP=0)
if(hour>12) h=hour-12;
else h=hour;
}
else h=hour; //che do 24h(AP=1)
}
//Ham hien thi time len LCD
void display_time_lcd(unsigned char x, unsigned char y){
lcd_gotoxy(x,y);
lcd_putchar(48+h/10); //hang chuc
lcd_putchar(48+h%10); // hang don vi
lcd_putsf(":");
lcd_putchar(48+min/10); //hang chuc
lcd_putchar(48+min%10); // hang don vi
lcd_putsf(":");
lcd_putchar(48+sec/10); //hang chuc
lcd_putchar(48+sec%10); // hang don vi
}
//Ham hien thi date len LCD
void display_date_lcd(unsigned char x, unsigned char y){
lcd_gotoxy(x,y);
lcd_putchar(48+date/10); //hang chuc
lcd_putchar(48+date%10); // hang don vi
lcd_putsf("/");
lcd_putchar(48+month/10); //hang chuc
lcd_putchar(48+month%10); // hang don vi
lcd_putsf("/");
lcd_putchar(48+year/10); //hang chuc
lcd_putchar(48+year%10); // hang don vi
display_day(day); //hien thi thu
}
//Ham hien thi o che do hen gio
void display_hengio_lcd(unsigned char x, unsigned char y){
lcd_gotoxy(x,y);
lcd_putchar(48+h_set/10); //hang chuc
lcd_putchar(48+h_set%10); // hang don vi
lcd_putsf(":");
lcd_putchar(48+m_set/10); //hang chuc
lcd_putchar(48+m_set%10); // hang don vi
}
void display_hengio_lcd1(unsigned char x, unsigned char y){
lcd_gotoxy(x,y);
lcd_putchar(48+h_set1/10); //hang chuc
lcd_putchar(48+h_set1%10); // hang don vi
lcd_putsf(":");
lcd_putchar(48+m_set1/10); //hang chuc
lcd_putchar(48+m_set1%10); // hang don vi
}
void display_hengio_lcd2(unsigned char x, unsigned char y){
lcd_gotoxy(x,y);
lcd_putchar(48+h_set2/10); //hang chuc
lcd_putchar(48+h_set2%10); // hang don vi
lcd_putsf(":");
lcd_putchar(48+m_set2/10); //hang chuc
lcd_putchar(48+m_set2%10); // hang don vi
}
void display_hengio_lcd3(unsigned char x, unsigned char y){
lcd_gotoxy(x,y);
lcd_putchar(48+h_set3/10); //hang chuc
lcd_putchar(48+h_set3%10); // hang don vi
lcd_putsf(":");
lcd_putchar(48+m_set3/10); //hang chuc
lcd_putchar(48+m_set3%10); // hang don vi
}
void display_hengio_lcd4(unsigned char x, unsigned char y){
lcd_gotoxy(x,y);
lcd_putchar(48+h_set4/10); //hang chuc
lcd_putchar(48+h_set4%10); // hang don vi
lcd_putsf(":");
lcd_putchar(48+m_set4/10); //hang chuc
lcd_putchar(48+m_set4%10); // hang don vi
}
void display_hengio_lcd7(unsigned char x, unsigned char y){
lcd_gotoxy(x,y);
lcd_putchar(48+h_led/10); //hang chuc
lcd_putchar(48+h_led%10); // hang don vi
lcd_putsf(":");
lcd_putchar(48+m_led/10); //hang chuc
lcd_putchar(48+m_led%10); // hang don vi
}
void display_hengio_lcd8(unsigned char x, unsigned char y){
lcd_gotoxy(x,y);
lcd_putchar(48+h_led1/10); //hang chuc
lcd_putchar(48+h_led1%10); // hang don vi
lcd_putsf(":");
lcd_putchar(48+m_led1/10); //hang chuc
lcd_putchar(48+m_led1%10); // hang don vi
}
//Ham hien thi tren LCD
void display_lcd(void) { //hien thi Time len LCD
lcd_gotoxy(0,0);
lcd_putsf("Time: "); //hien thi thoi gian
display_time_lcd(6,0);
// hien thi date len LCD
lcd_gotoxy(0,1);
lcd_putsf("Date: ");
display_date_lcd(6,1);
}
void bitbit()
{
{
PORTD.6=0;
delay_ms(50);
PORTD.6=1;
delay_ms(50);
}
PORTD.6=1;
}
//Chuong trinh kiem tra phim nhan
void status_button(void){
if(MODE&&UP&&DOWN&&OFF&&sb&&MODE2){
sb=0; //kiem tr phim da nha chua
}
}
//Ham kiem tra so ngay trong thang
void Ndate_in_month(void){
if(month==2){
if(year%4==0) No_date=29;
else No_date=28;
}
else if(month==1||month==3||month==5||month==7||month== 8||month==10||month==12) No_date=31;
else No_date=30;
}
//Ham cai dat thoi gian va bao thuc
void set_alarm_time(void){
status_button();
// chuyen doi che do 12h<==>24h
if ((OFF==0)&&(sb==0)){
AP=~AP; // doi che do gio hien thi
sb=1; //bao co phim nhan
}
status_button();
// chon che do nguoi dung
if(MODE==0&&sb==0){
//chon che do
if(mode==27){
mode=1;
}
else{
mode++;
}
sb=1;
}
//che do mode=0 hien thong tin
if(mode==0){
lcd_gotoxy(0,0);
lcd_putsf("DO AN");
lcd_gotoxy(0,1);
lcd_putsf(" VTK40 ");
delay_ms(2000); // tu chuyen sang che do binh thuong
mode++;
}
//che do mode=1 hien thi binh thuong
if(mode==1){
lcd_clear();
display_lcd();
}
//che do mode=2 chinh gio
if(mode==2){
lcd_clear();
// che do chinh gio
lcd_gotoxy(0,0);
lcd_putsf("SET GIO: ");
lcd_putsf(" ");
display_time_lcd(5,1);
lcd_putsf(" ");
status_button();
if(UP==0&&sb==0){
// phim UP duoc nhan
if(hour==23) hour=0;
else hour++;
rtc_set_time(hour,min,sec); //Dat lai gio cho DS1307
sb=1;
}
status_button();
if(DOWN==0&&sb==0){
if(hour==0) hour=23;
else hour--;
rtc_set_time(hour,min,sec);
sb=1;
}
}
if(mode==3){
// che do chinh phut
lcd_clear();
lcd_gotoxy(0,0);
lcd_putsf("SET PHUT: ");
lcd_putsf(" ");
display_time_lcd(5,1);
lcd_putsf(" ");
status_button();
if(UP==0&&sb==0){
// phim UP duoc nhan
if(min==59) min=0;
else min++;
rtc_set_time(hour,min,sec); //Dat lai phut cho DS1307
sb=1;
}
status_button();
if(DOWN==0&&sb==0){
if(min==0) min=59;
else min--;
rtc_set_time(hour,min,sec);
sb=1;
}
}
//che do mode=5 chinh thu va ngay
if(mode==4){
lcd_clear();
lcd_gotoxy(0,0);
lcd_putsf("SET NGAY: ");
lcd_putsf(" ");
display_date_lcd(5,1);
lcd_putsf(" ");
Ndate_in_month();
status_button();
if(UP==0&&sb==0){
// phim UP duoc nhan
if(day==7) day=1;
else day++;
// xac dinh ngay(date) khi chinh thu
if(date==No_date){
if(month==12){ //chuyen sang nam moi
date=1;
month=1;
year++;
}
else{
date=1;month++; // het thang thi sang thang moi
}
}
else date++;
rtc_set_date(day,date,month,year);
sb=1;
}
status_button();
if(DOWN==0&&sb==0){
if(day==1) day=7;
else day--;
if(date==1){
//VD 1/3 chuyen thanh 28(19)/2
if(month==1){
month=12;date=31;year--;
}
else{
month--;
Ndate_in_month();
date=No_date;
}
}
else date--;
rtc_set_date(day,date,month,year);
sb=1;
}
}
//che do mode=6 chinh thang
if(mode==5){
// che do chinh thang
lcd_clear();
lcd_gotoxy(0,0);
lcd_putsf("SET THANG: ");
lcd_putsf(" ");
display_date_lcd(5,1);
lcd_putsf(" ");
Ndate_in_month();
status_button();
if(UP==0&&sb==0){
// phim UP duoc nhan
if(month==12){
month=1;
if(year==99) year=0;
else year++;
}
else month++;
//xac dinh thu(day) khi chinh thang(month)
if((day+No_date%7)>7)
day=day+No_date%7-7;
else day=day+No_date%7;
Ndate_in_month(); // cap nhat so ngay toi da cua thang cua dat lai
if(date>No_date) date=No_date;
//31/3 phai thanh 30/4 khi nhan UP
rtc_set_date(day,date,month,year);
sb=1;
}
status_button();
if(DOWN==0&&sb==0){
if(month==1){
hour=12;
if(year==0) year=99;
else year--;
}
else month--;
Ndate_in_month();
// kiem tra tinh theo so ngay thang truoc de xac dinh thu
if(day<No_date%7) day=day-No_date%7+7;
else day=day-No_date%7;
if(date>No_date) date=No_date;
// VD tu 31/3 phai thanh 29/2 khi an DOWN(month)
rtc_set_date(day,date,month,year);
sb=1;
}
}
//che do mode=7 chinh nam
if(mode==6){
lcd_clear();
// che do chinh name
lcd_gotoxy(0,0);
lcd_putsf("SET NAM: ");
lcd_putsf(" ");
display_date_lcd(5,1);
lcd_putsf(" ");
status_button();
if(UP==0&&sb==0){
// phim UP duoc nhan
if((year%4==0)&&(month==1)&&(date==29))
{
//ngay 29/2 nam nhuan
date=28;
}
// chinh thu(day) khi chuyen nam
if(year%4==0){ //nam nhuan
if((month==1)||((month==2)&&(date<29)))
{
if(day==7) // thu 8
day=2; //thu 3
else day=day+2;
}
else day=day+1; // nam nhuan nhung thu chi tang 1 ngay
}
else day=day+1; // ko phai nam nhuan
// chuyen nam
if(year==99)
year=0;
else year++;
rtc_set_date(day,date,month,year);
sb=1;
}
status_button();
if(DOWN==0&&sb==0){
if(year%4==0){ //nam nhuan
if((month>2)||((month==2)&&(date==29)))
{
if(day==1) // thu 2
day=6; // thu 7
else day-=2;
}
else day-=1; // nam nhuan nhung thu chi lui 1 ngay
}
else day-=1; // khong phai nam nhuan
// chuyen ngay cua thang 2 khi chuyen thu nam nhuan sang nam ko nhuan
if((year%4==0)&&((month==2)&&(date==29)))
{
// ngay 29/2 nam nhuan
date=28;
}
// chinh nam
if(year==0) year=99;
else year--;
rtc_set_date(day,date,month,year);
sb=1;
}
}
// che do mode=8 chinh gio trong che do hen gio
if(mode==7){
lcd_clear();
lcd_gotoxy(0,0);
lcd_clear();
lcd_putsf("BTHUC1: ");
display_hengio_lcd(8,0);
lcd_gotoxy(0,1);
lcd_putsf("GIO: ");
lcd_gotoxy(8,1);
lcd_putchar(h_set/10+48);
lcd_putchar(h_set%10+48);
lcd_putsf(" ");
status_button();
if(UP==0&&sb==0){
if(h_set==23) h_set=0;
else h_set++;
sb=1;
}
status_button();
if(DOWN==0&&sb==0){
if(h_set==0) h_set=23;
else h_set--;
sb=1;
}
}
//che do mode=8 chinh phut trong che do hen gio
if(mode==8){
lcd_clear();
// che do chinh phut
lcd_gotoxy(0,0);
lcd_putsf("BTHUC1: ");
display_hengio_lcd(8,0);
lcd_gotoxy(0,1);
lcd_putsf("PHUT: ");
lcd_gotoxy(8,1);
lcd_putchar(m_set/10+48);
lcd_putchar(m_set%10+48);
lcd_putsf(" ");
status_button();
if(UP==0&&sb==0){
// phim UP duoc nhan
if(m_set==59) m_set=0;
else m_set++;
sb=1;
}
status_button();
if(DOWN==0&&sb==0){
if(m_set==0) m_set=59;
else m_set--;
sb=1;
}
}
if(mode==9){
lcd_clear();
lcd_gotoxy(0,0);
lcd_putsf(" BTHUC1 ");
lcd_gotoxy(0,1);
lcd_putsf("RING: ");
lcd_gotoxy(8,1);
lcd_putchar(m_ring/10+48);
lcd_putchar(m_ring%10+48);
lcd_putsf(" ");
status_button();
if(UP==0&&sb==0){
// phim UP duoc nhan
if(m_ring==59) m_ring=0;
else m_ring++;
sb=1;
}
status_button();
if(DOWN==0&&sb==0){
if(m_ring==0) m_ring=59;
else m_ring--;
sb=1;
}
}
if(mode==10){
lcd_clear();
lcd_gotoxy(0,0);
lcd_putsf("BAO THUC 1 ???");
lcd_gotoxy(0,1);
lcd_putsf(" ");
if(UP==0&&sb==0){
alarm_en=1;
lcd_gotoxy(0,1);
lcd_putsf("ON ");
}
if(DOWN==0&&sb==0)
{
alarm_en=0;
lcd_gotoxy(0,1);
lcd_putsf("OFF");
}
}
if(mode==11){
lcd_clear();
lcd_gotoxy(0,0);
lcd_putsf("BTHUC2: ");
display_hengio_lcd1(8,0);
lcd_gotoxy(0,1);
lcd_putsf("GIO: ");
lcd_gotoxy(8,1);
lcd_putchar(h_set1/10+48);
lcd_putchar(h_set1%10+48);
lcd_putsf(" ");
status_button();
if(UP==0&&sb==0){
if(h_set1==23) h_set1=0;
else h_set1++;
sb=1;
}
status_button();
if(DOWN==0&&sb==0){
if(h_set1==0) h_set1=23;
else h_set1--;
sb=1;
}
}
//che do mode=8 chinh phut trong che do hen gio
if(mode==12){
lcd_clear();
// che do chinh phut
lcd_gotoxy(0,0);
lcd_putsf("BTHUC2: ");
display_hengio_lcd1(8,0);
lcd_gotoxy(0,1);
lcd_putsf("PHUT: ");
lcd_gotoxy(8,1);
lcd_putchar(m_set1/10+48);
lcd_putchar(m_set1%10+48);
lcd_putsf(" ");
status_button();
if(UP==0&&sb==0){
// phim UP duoc nhan
if(m_set1==59) m_set1=0;
else m_set1++;
sb=1;
}
status_button();
if(DOWN==0&&sb==0){
if(m_set1==0) m_set1=59;
else m_set1--;
sb=1;
}
}
if(mode==13){
lcd_clear();
lcd_gotoxy(0,0);
lcd_putsf(" BTHUC2 ");
lcd_gotoxy(0,1);
lcd_putsf("RING: ");
lcd_gotoxy(8,1);
lcd_putchar(m_ring1/10+48);
lcd_putchar(m_ring1%10+48);
lcd_putsf(" ");
status_button();
if(UP==0&&sb==0){
// phim UP duoc nhan
if(m_ring1==59) m_ring1=0;
else m_ring1++;
sb=1;
}
status_button();
if(DOWN==0&&sb==0){
if(m_ring1==0) m_ring1=59;
else m_ring1--;
sb=1;
}
}
if(mode==14){
lcd_clear();
lcd_gotoxy(0,0);
lcd_putsf("BAO THUC 2 ???");
lcd_gotoxy(0,1);
lcd_putsf(" ");
if(UP==0&&sb==0){
alarm_en1=1;
lcd_gotoxy(0,1);
lcd_putsf("ON ");
}
if(DOWN==0&&sb==0)
{
alarm_en1=0;
lcd_gotoxy(0,1);
lcd_putsf("OFF");
}
}
if(mode==15){
lcd_clear();
lcd_gotoxy(0,0);
lcd_putsf("BTHUC3: ");
display_hengio_lcd2(8,0);
lcd_gotoxy(0,1);
lcd_putsf("GIO: ");
lcd_gotoxy(8,1);
lcd_putchar(h_set2/10+48);
lcd_putchar(h_set2%10+48);
lcd_putsf(" ");
status_button();
if(UP==0&&sb==0){
if(h_set2==23) h_set2=0;
else h_set2++;
sb=1;
}
status_button();
if(DOWN==0&&sb==0){
if(h_set2==0) h_set2=23;
else h_set2--;
sb=1;
}
}
//che do mode=8 chinh phut trong che do hen gio
if(mode==16){
lcd_clear();
// che do chinh phut
lcd_gotoxy(0,0);
lcd_putsf("BTHUC3:");
display_hengio_lcd2(8,0);
lcd_gotoxy(0,1);
lcd_putsf("PHUT: ");
lcd_gotoxy(8,1);
lcd_putchar(m_set2/10+48);
lcd_putchar(m_set2%10+48);
lcd_putsf(" ");
status_button();
if(UP==0&&sb==0){
// phim UP duoc nhan
if(m_set2==59) m_set2=0;
else m_set2++;
sb=1;
}
status_button();
if(DOWN==0&&sb==0){
if(m_set2==0) m_set2=59;
else m_set2--;
sb=1;
}
}
if(mode==17){
lcd_clear();
lcd_gotoxy(0,0);
lcd_putsf(" BTHUC3 ");
lcd_gotoxy(0,1);
lcd_putsf("RING: ");
lcd_gotoxy(8,1);
lcd_putchar(m_ring2/10+48);
lcd_putchar(m_ring2%10+48);
lcd_putsf(" ");
status_button();
if(UP==0&&sb==0){
// phim UP duoc nhan
if(m_ring2==59) m_ring2=0;
else m_ring2++;
sb=1;
}
status_button();
if(DOWN==0&&sb==0){
if(m_ring2==0) m_ring2=59;
else m_ring2--;
sb=1;
}
}
if(mode==18){
lcd_clear();
lcd_gotoxy(0,0);
lcd_putsf("BAO THUC 3 ???");
lcd_gotoxy(0,1);
lcd_putsf(" ");
if(UP==0&&sb==0){
alarm_en2=1;
lcd_gotoxy(0,1);
lcd_putsf("ON ");
}
if(DOWN==0&&sb==0)
{
alarm_en2=0;
lcd_gotoxy(0,1);
lcd_putsf("OFF");
}
}
if(mode==19){
lcd_clear();
lcd_gotoxy(0,0);
lcd_putsf("BTHUC4: ");
display_hengio_lcd3(8,0);
lcd_gotoxy(0,1);
lcd_putsf("GIO: ");
lcd_gotoxy(8,1);
lcd_putchar(h_set3/10+48);
lcd_putchar(h_set3%10+48);
lcd_putsf(" ");
status_button();
if(UP==0&&sb==0){
if(h_set3==23) h_set3=0;
else h_set3++;
sb=1;
}
status_button();
if(DOWN==0&&sb==0){
if(h_set3==0) h_set3=23;
else h_set3--;
sb=1;
}
}
//che do mode=8 chinh phut trong che do hen gio
if(mode==20){
lcd_clear();
// che do chinh phut
lcd_gotoxy(0,0);
lcd_putsf("BTHUC4:");
display_hengio_lcd3(8,0);
lcd_gotoxy(0,1);
lcd_putsf("PHUT: ");
lcd_gotoxy(8,1);
lcd_putchar(m_set3/10+48);
lcd_putchar(m_set3%10+48);
lcd_putsf(" ");
status_button();
if(UP==0&&sb==0){
// phim UP duoc nhan
if(m_set3==59) m_set3=0;
else m_set3++;
sb=1;
}
status_button();
if(DOWN==0&&sb==0){
if(m_set3==0) m_set3=59;
else m_set3--;
sb=1;
}
}
if(mode==21){
lcd_clear();
lcd_gotoxy(0,0);
lcd_putsf(" BTHUC4 ");
lcd_gotoxy(0,1);
lcd_putsf("RING: ");
lcd_gotoxy(8,1);
lcd_putchar(m_ring3/10+48);
lcd_putchar(m_ring3%10+48);
lcd_putsf(" ");
status_button();
if(UP==0&&sb==0){
// phim UP duoc nhan
if(m_ring3==59) m_ring3=0;
else m_ring3++;
sb=1;
}
status_button();
if(DOWN==0&&sb==0){
if(m_ring3==0) m_ring3=59;
else m_ring3--;
sb=1;
}
}
if(mode==22){
lcd_clear();
lcd_gotoxy(0,0);
lcd_putsf("BAO THUC 4 ???");
lcd_gotoxy(0,1);
lcd_putsf(" ");
if(UP==0&&sb==0){
alarm_en3=1;
lcd_gotoxy(0,1);
lcd_putsf("ON ");
}
if(DOWN==0&&sb==0)
{
alarm_en3=0;
lcd_gotoxy(0,1);
lcd_putsf("OFF");
}
}
if(mode==23){
lcd_clear();
lcd_gotoxy(0,0);
lcd_putsf("BTHUC5: ");
display_hengio_lcd4(8,0);
lcd_gotoxy(0,1);
lcd_putsf("GIO: ");
lcd_gotoxy(8,1);
lcd_putchar(h_set4/10+48);
lcd_putchar(h_set4%10+48);
lcd_putsf(" ");
status_button();
if(UP==0&&sb==0){
if(h_set4==23) h_set4=0;
else h_set4++;
sb=1;
}
status_button();
if(DOWN==0&&sb==0){
if(h_set4==0) h_set4=23;
else h_set4--;
sb=1;
}
}
//che do mode=8 chinh phut trong che do hen gio
if(mode==24){
lcd_clear();
// che do chinh phut
lcd_gotoxy(0,0);
lcd_putsf("BTHUC5:");
display_hengio_lcd4(8,0);
lcd_gotoxy(0,1);
lcd_putsf("PHUT: ");
lcd_gotoxy(8,1);
lcd_putchar(m_set4/10+48);
lcd_putchar(m_set4%10+48);
lcd_putsf(" ");
status_button();
if(UP==0&&sb==0){
// phim UP duoc nhan
if(m_set4==59) m_set4=0;
else m_set4++;
sb=1;
}
status_button();
if(DOWN==0&&sb==0){
if(m_set4==0) m_set4=59;
else m_set4--;
sb=1;
}
}
if(mode==25){
lcd_clear();
lcd_gotoxy(0,0);
lcd_putsf(" BTHUC5 ");
lcd_gotoxy(0,1);
lcd_putsf("RING: ");
lcd_gotoxy(8,1);
lcd_putchar(m_ring4/10+48);
lcd_putchar(m_ring4%10+48);
lcd_putsf(" ");
status_button();
if(UP==0&&sb==0){
// phim UP duoc nhan
if(m_ring4==59) m_ring4=0;
else m_ring4++;
sb=1;
}
status_button();
if(DOWN==0&&sb==0){
if(m_ring4==0) m_ring4=59;
else m_ring4--;
sb=1;
}
}
if(mode==26){
lcd_clear();
lcd_gotoxy(0,0);
lcd_putsf("BAO THUC 5 ???");
lcd_gotoxy(0,1);
lcd_putsf(" ");
if(UP==0&&sb==0){
alarm_en4=1;
lcd_gotoxy(0,1);
lcd_putsf("ON ");
}
if(DOWN==0&&sb==0)
{
alarm_en4=0;
lcd_gotoxy(0,1);
lcd_putsf("OFF");
}
}
}
void baothuc(){
if(((alarm_en==1)&&(hour==h_set)&&(min==m_set))||( (alarm_en1==1)&&(hour==h_set1)&&(min==m_set1))||(( alarm_en2==1)&&(hour==h_set2)&&(min==m_set2))||((a larm_en3==1)&&(hour==h_set3)&&(min==m_set3))||((al arm_en4==1)&&(hour==h_set4)&&(min==m_set4)))
{
bitbit();
}
if(min==m_ring&&hour==h_set)
{
PORTD.6=0;
}
if(min==m_ring1&&hour==h_set1)
{
PORTD.6=0;
}
if(min==m_ring2&&hour==h_set2)
{
PORTD.6=0;
}
if(min==m_ring3&&hour==h_set3)
{
PORTD.6=0;
}
if(min==m_ring4&&hour==h_set4)
{
PORTD.6=0;
}
status_button();
if(OFF==0&&sb==0){
PORTD.6=0;
alarm_en=0;alarm_en1=0;alarm_en2=0;alarm_en3=0;ala rm_en4=0;
sb=1;
}
}
void set_led_time(void){
if(MODE2==0&&sb==0){
mode=27;
//chon che do
if(mode2==6){
mode2=0;
mode=1;
}
else{
mode2++;
}
sb=1;
}
if(mode2==1){
lcd_clear();
lcd_gotoxy(0,0);
lcd_putsf("LEDON: ");
display_hengio_lcd7(8,0);
lcd_gotoxy(0,1);
lcd_putsf("GIO: ");
lcd_gotoxy(8,1);
lcd_putchar(h_led/10+48);
lcd_putchar(h_led%10+48);
lcd_putsf(" ");
status_button();
if(UP==0&&sb==0){
if(h_led==23) h_led=0;
else h_led++;
sb=1;
}
status_button();
if(DOWN==0&&sb==0){
if(h_led==0) h_led=23;
else h_led--;
sb=1;
}
}
if(mode2==2){
lcd_gotoxy(0,0);
lcd_putsf("LEDON: ");
display_hengio_lcd7(8,0);
lcd_gotoxy(0,1);
lcd_putsf("PHUT: ");
lcd_gotoxy(8,1);
lcd_putchar(m_led/10+48);
lcd_putchar(m_led%10+48);
lcd_putsf(" ");
status_button();
if(UP==0&&sb==0){
if(m_led==59) m_led=0;
else m_led++;
sb=1;
}
status_button();
if(DOWN==0&&sb==0){
if(m_led==0) m_led=59;
else m_led--;
sb=1;
}
}
if(mode2==3){
lcd_gotoxy(0,0);
lcd_putsf("LEDOF: ");
display_hengio_lcd8(8,0);
lcd_gotoxy(0,1);
lcd_putsf("GIO: ");
lcd_gotoxy(8,1);
lcd_putchar(h_led1/10+48);
lcd_putchar(h_led1%10+48);
lcd_putsf(" ");
status_button();
if(UP==0&&sb==0){
if(h_led1==23) h_led1=0;
else h_led1++;
sb=1;
}
status_button();
if(DOWN==0&&sb==0){
if(h_led1==0) h_led1=23;
else h_led1--;
sb=1;
}
}
if(mode2==4){
lcd_gotoxy(0,0);
lcd_putsf("LEDOF: ");
display_hengio_lcd8(8,0);
lcd_gotoxy(0,1);
lcd_putsf("PHUT: ");
lcd_gotoxy(8,1);
lcd_putchar(m_led1/10+48);
lcd_putchar(m_led1%10+48);
lcd_putsf(" ");
status_button();
if(UP==0&&sb==0){
if(m_led1==59) m_led1=0;
else m_led1++;
sb=1;
}
status_button();
if(DOWN==0&&sb==0){
if(m_led1==0) m_led1=59;
else m_led1--;
sb=1;
}
}
if(mode2==5){
lcd_gotoxy(0,0);
lcd_putsf("BAT DEN HAY KO");
lcd_gotoxy(0,1);
lcd_putsf(" ");
if(UP==0&&sb==0){
led_en=1;
PORTD.7=1;
lcd_gotoxy(0,1);
lcd_putsf("ON ");
}
if(DOWN==0&&sb==0)
{
led_en=0;
PORTD.7=0;
lcd_gotoxy(0,1);
lcd_putsf("OFF");
}
}
}
void battatled(){
if((h_led==hour)&&(m_led==min)&&(led_en==1))
{
PORTD.7=1;
}
if((h_led1==hour)&&(m_led1==min))
{
PORTD.7=0;
}
status_button();
if(OFF==0&&sb==0){
led_en=0;
sb=1;
}
}
void main(void)
{
// Input/Output Ports initialization
// Port B initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTB=0x00;
DDRB=0x00;
// Port C initialization
// Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTC=0x00;
DDRC=0x00;
// Port D initialization
// Func7=Out Func6=Out Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=0 State6=0 State5=T State4=T State3=T State2=T State1=T State0=T
PORTD=0x00;
DDRD=0xC0;
// Timer/Counter 0 initialization
// Clock source: System Clock
// Clock value: Timer 0 Stopped
TCCR0=0x00;
TCNT0=0x00;
// Timer/Counter 1 initialization
// Clock source: System Clock
// Clock value: Timer1 Stopped
// Mode: Normal top=0xFFFF
// OC1A output: Discon.
// OC1B output: Discon.
// Noise Canceler: Off
// Input Capture on Falling Edge
// Timer1 Overflow Interrupt: Off
// Input Capture Interrupt: Off
// Compare A Match Interrupt: Off
// Compare B Match Interrupt: Off
TCCR1A=0x00;
TCCR1B=0x00;
TCNT1H=0x00;
TCNT1L=0x00;
ICR1H=0x00;
ICR1L=0x00;
OCR1AH=0x00;
OCR1AL=0x00;
OCR1BH=0x00;
OCR1BL=0x00;
// Timer/Counter 2 initialization
// Clock source: System Clock
// Clock value: Timer2 Stopped
// Mode: Normal top=0xFF
// OC2 output: Disconnected
ASSR=0x00;
TCCR2=0x00;
TCNT2=0x00;
OCR2=0x00;
// External Interrupt(s) initialization
// INT0: Off
// INT1: Off
MCUCR=0x00;
// Timer(s)/Counter(s) Interrupt(s) initialization
TIMSK=0x00;
// USART initialization
// USART disabled
UCSRB=0x00;
// Analog Comparator initialization
// Analog Comparator: Off
// Analog Comparator Input Capture by Timer/Counter 1: Off
ACSR=0x80;
SFIOR=0x00;
// ADC initialization
// ADC disabled
ADCSRA=0x00;
// SPI initialization
// SPI disabled
SPCR=0x00;
// TWI initialization
// TWI disabled
TWCR=0x00;
// I2C Bus initialization
// I2C Port: PORTC
// I2C SDA bit: 1
// I2C SCL bit: 0
// Bit Rate: 100 kHz
// Note: I2C settings are specified in the
// Project|Configure|C Compiler|Libraries|I2C menu.
i2c_init();
// DS1307 Real Time Clock initialization
// Square wave output on pin SQW/OUT: On
// Square wave frequency: 32768Hz
rtc_init(3,1,0);
// Alphanumeric LCD initialization
// Connections are specified in the
// Project|Configure|C Compiler|Libraries|Alphanumeric LCD menu:
// RS - PORTB Bit 0
// RD - PORTB Bit 1
// EN - PORTB Bit 2
// D4 - PORTB Bit 4
// D5 - PORTB Bit 5
// D6 - PORTB Bit 6
// D7 - PORTB Bit 7
// Characters/line: 16
lcd_init(16);
sb=0; //mac dinh la ko co nut bam
while (1)
{
// Place your code here
// Place your code here
rtc_get_time(&hour,&min,&sec);
// doc gio, phut, day tu DS1307
rtc_get_date(&day,&date,&month,&year);
// doc ngay thang nam tu DS1307
check_conveter_day(); //kiem tra va chuyen sang mac dinh
check_conveter_hour();
status_button();
set_alarm_time();
baothuc();
set_led_time();
battatled();
}
}