em đang chuẩn bị làm mạch thật cái ds1307 và avr nhưng ko biết viết code chỉnh giờ như thế nào mong các anh giúp vơi, có 1 nút mode để chọn và 1 nút tăng giảm nữa là được rồi, với lại các anh chỉ em code chống trôi phím luôn với9.zip
code chỉnh giờ và chống trôi phím
Collapse
X
-
Nếu bạn làm hiển thị với LCD thì có thể tham khảo đoạn code này, đây là 1 file trong project của mình, với chức năng change_time();
Code này viết trên CCS.Code:/* ************************************************************************************************************************************* * SETUP TIME * ************************************************************************************************************************************* */ void set_time(int8 selection) { int8 temp; LCD_Cmd(0x01); if (selection==1) { LCD_Char("SETTING TIME MODE"); LCD_Position(0x40); LCD_Char("Hour: "); int hou= read_ds1307(2); temp=hou; } if (selection==2) { LCD_Char("SETTING TIME MODE"); LCD_Position(0x40); LCD_Char("Minute: "); int min= read_ds1307(1); temp=min; } if (selection==3) { LCD_Char("SETTING TIME MODE"); LCD_Position(0x40); LCD_Char("Date: "); int date= read_ds1307(4); temp=date; } if (selection==4) { LCD_Char("SETTING TIME MODE"); LCD_Position(0x40); LCD_Char("Month: "); int mon= read_ds1307(5); temp=mon; } if (selection==5) { LCD_Char("SETTING TIME MODE"); LCD_Position(0x40); LCD_Char("Year: "); int year= read_ds1307(6); temp=year; } if (selection==6) { LCD_Char("SETTING TIME MODE"); LCD_Position(0x40); LCD_Char("Day: "); int day= read_ds1307(3); temp=day; } LCD_Position(0x49); temp=bcdToDec(temp); printf(LCD_Char, "%u" , temp); while(1){ LCD_Position(0x49); printf(LCD_Char, "%u" , temp); if ( !input(up)) { delay_ms(300); temp++; if( selection==1 && temp==24 ) {temp=0; LCD_Position(0x49);; LCD_Char(" ");} if( selection==2 && temp==60 ) {temp=0; LCD_Position(0x49); LCD_Char(" ");} if( selection==3 && temp==32 ) {temp=1; LCD_Position(0x49); LCD_Char(" ");} if( selection==4 && temp==13 ) {temp=1; LCD_Position(0x49); LCD_Char(" ");} if( selection==5 && temp==100 ) {temp=0; LCD_Position(0x49); LCD_Char(" ");} if( selection==6 && temp==8 ) {temp=1; LCD_Position(0x49); LCD_Char(" ");} } if ( !input(down)) { delay_ms(300); if( selection==1&& temp==0 ) {temp=24; LCD_Position(0x49); LCD_Char(" ");} if( selection==2 && temp==0 ) {temp=60; LCD_Position(0x49); LCD_Char(" ");} if( selection==3 && temp==1 ) {temp=32; LCD_Position(0x49); LCD_Char(" ");} if( selection==4 && temp==1 ) {temp=13; LCD_Position(0x49); LCD_Char(" ");} if( selection==5 && temp==0 ) {temp=100; LCD_Position(0x49); LCD_Char(" ");} if( selection==6 && temp==1 ) {temp=8; LCD_Position(0x49); LCD_Char(" ");} if (temp==10) { LCD_Position(0x49);; LCD_Char(" "); } temp--; } if ( !input(mode)){ delay_ms(400); select_time=7; break; } if ( !input(set)) { delay_ms(400); select_time++; if(select_time==7) select_time=1;break; } } if (selection==1) { hou=decToBcd((int8)temp); write_ds1307(2,hou); } if (selection==2) { min=decToBcd((int8)temp); write_ds1307(1,min); } if (selection==3) { date=decToBcd((int8)temp); write_ds1307(4,date); } if (selection==4) { mon=decToBcd((int8)temp); write_ds1307(5,mon); } if (selection==5) { year=decToBcd((int8)temp); write_ds1307(6,year); } if (selection==6) { day=decToBcd((int8)temp); write_ds1307(3,day); } } void change_time() { switch (select_time) { Case 1: set_time(1); break; Case 2: set_time(2); break; Case 3: set_time(3); break; Case 4: set_time(4); break; Case 5: set_time(5); break; Case 6: set_time(6); break; Case 7: menu=3; select_time=1; break; } }
ThânWeb:
->Nhận thiết kế, hoàn thiện dự án, sản phẩm điện tử<-
-->Giải pháp GSM/GPRS/GPS - Công nghệ RFID<--
-
bạn có thể dùng ngắt. mỗi khi có ngắt tăng biến lên 1 đơn vị và tương ứng vs mỗi giá trị của biến đó là bạn cho nó 1 nhiệm vụ nhất định ví dụ x=1 settime.... kết hợp thêm phím up và down trong mỗi sự kiện nữa là ok rồi.Nguyễn Huy Biên - 01649 802 694
gmail :
Comment
-
đây là cách của mình viết hàm thay thế ngắt :
code :
bit a,sb ; //khai báo biến a,sb có kiểu bit(0 ,1)
DDRA.0=0;//thiết lập porta.0 là nút nhấn
if(sb&&PORTA.0==1)
{
sb=0; //ham kiem tra phim nhan
}
if(sb=0&&PORTA.0=0)
{
a=~a;//thực hiện công việc của bạn ở đây mình đảo bít a
}
Comment
Bài viết mới nhất
Collapse
-
Trả lời cho Nhờ ae hướng dẫn sửa máy bắn cosbởi Nexus 6PE k biết vẽ nên mới đi hỏi nè
-
Channel: Điện tử dành cho người mới bắt đầu
hôm nay, 09:13 -
-
bởi thaodmttChào các bác kỹ sư nhúng,
Hôm nay mình muốn trao đổi về vấn đề an toàn khi nạp firmware từ xa (FOTA). Khi triển khai hàng trăm thiết bị ở xa, rủi ro lớn nhất là đang cập nhật firmware thì mất điện hoặc rớt mạng giữa chừng khiến...-
Channel: Hệ thống nhúng
02-10-2026, 15:01 -

Comment