#include
#include
#define uchar unsigned char
#define uint unsigned int
#define DS_ PORTC&=~BIT(6)
#define DS PORTC|=BIT(6)
#define RW_ PORTC&=~BIT(5)
#define RW PORTC|=BIT(5)
#define AS_ PORTC&=~BIT(4)
#define AS PORTC|=BIT(4)
#define CS_ PORTC&=~BIT(3)
#define CS PORTC|=BIT(3)
uchar tab1[]={"DAT:"};
uchar tab2[]={"TIME:"};
const uchar tab[]={0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x3a,0x20};
extern uchar dat[]={0x32,0x30,0x31,0x31,0x2d,0x39,0x39,0x2d,0x30,0x36};
extern uchar time[8]={0x30,0x30,0x2d,0x30,0x30,0x2d,0x30,0x30};
uchar sec=0,min=0,hou=0,day=0,mon=0,yea=0,week=0;
void delay(uint z)
{
while(z--);
}
void disan()
{
uchar hlb;
hlb=hou;
dat[0x00]=2+0x30;
dat[0x01]=0+0x30;
dat[0x02]=yea%100/10+0x30;
dat[0x03]=yea%16+0x30;
dat[0x05]=mon/16+0x30;
dat[0x06]=mon%16+0x30;
dat[0x08]=day/16+0x30;
dat[0x09]=day%16+0x30;
time[0x00]=hou/16+0x30;
time[0x01]=hou%16+0x30;
time[0x03]=min/16+0x30;
time[0x04]=min%16+0x30;
time[0x06]=sec/16+0x30;
time[0x07]=sec%16+0x30;
}
void write_com(uchar com)
{
PORTC&=~BIT(2);
PORTC&=~BIT(1);
PORTB=com;
PORTC|=BIT(0);
delay(1);
PORTC&=~BIT(0);
delay(3);
}
void write_dat(uchar dat)
{
PORTC|=BIT(2);
PORTC&=~BIT(1);
PORTB=dat;
PORTC|=BIT(0);
delay(1);
PORTC&=~BIT(0);
delay(3);
}
void init()
{
write_com(0X38);
delay(5);
write_com(0X0c);
delay(5);
write_com(0X06);
delay(5);
}
void write_ds(uchar add,uchar date)
{
CS_;
RW;
DS;
AS;
PORTA=add;
AS_;
RW_;
PORTA=date;
delay(1);
RW;
AS;
CS;
}
uchar read_ds(uchar add)
{
uchar ds_date;
CS_;
DS;
RW;
AS;
PORTA=add;
AS_;
DS_;
DDRA=0X00;
delay(1);
ds_date=PINA;
DDRA=0XFF;
DS;
AS;
CS;
return ds_date;
}
void ds12887()
{
sec=read_ds(0);
min=read_ds(2);
hou=read_ds(4);
day=read_ds(7);
mon=read_ds(8);
week=read_ds(6);
yea=read_ds(9);
}
void display()
{
uchar i;
init();
write_com(0X80);
delay(5);
for(i=0;i<4;i++)
{
write_dat(tab1[i]);
delay(5);
}
for(i=0;i<10;i++)
{
write_dat(dat[i]);
delay(5);
}
write_com(0X80+0X40);
delay(5);
for(i=0;i<5;i++)
{
write_dat(tab2[i]);
delay(5);
}
for(i=0;i<8;i++)
{
write_dat(time[i]);
delay(5);
}
write_dat(0x20);
delay(5);
write_dat(0x20);
delay(5);
write_dat(0x30+week);
delay(5);
}
void key_set()
{
write_ds(9,0x11);
write_ds(8,0x11);
write_ds(7,0x03);
write_ds(6,0x06);
write_ds(4,0x18);
write_ds(2,0x45);
write_ds(0,0x50);
}
void main()
{
MCUCSR |= 1<
DDRB=0XFF;
DDRC=0XFF;
write_com(0X01);
write_com(0X03);
/////////////////
write_ds(0x0b,0x02);
//key_set();
while(1)
{
ds12887();
disan();
display();
delay(1000);
}
}
Previous article:The ATmega16 MCU scientific calculator program (with addition, subtraction, multiplication and division functions) has been completed
Next article:Advanced experience with ultra-low power consumption of AVR microcontrollers
- Popular Resources
- Popular amplifiers
- Naxin Micro and Xinxian jointly launched the NS800RT series of real-time control MCUs
- How to learn embedded systems based on ARM platform
- Summary of jffs2_scan_eraseblock issues
- Application of SPCOMM Control in Serial Communication of Delphi7.0
- Using TComm component to realize serial communication in Delphi environment
- Bar chart code for embedded development practices
- Embedded Development Learning (10)
- Embedded Development Learning (8)
- Embedded Development Learning (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Intel promotes AI with multi-dimensional efforts in technology, application, and ecology
- ChinaJoy Qualcomm Snapdragon Theme Pavilion takes you to experience the new changes in digital entertainment in the 5G era
- Infineon's latest generation IGBT technology platform enables precise control of speed and position
- Two test methods for LED lighting life
- Don't Let Lightning Induced Surges Scare You
- Application of brushless motor controller ML4425/4426
- Easy identification of LED power supply quality
- World's first integrated photovoltaic solar system completed in Israel
- Sliding window mean filter for avr microcontroller AD conversion
- What does call mean in the detailed explanation of ABB robot programming instructions?
- Infineon Technologies Launches ModusToolbox™ Motor Kit to Simplify Motor Control Development
- Infineon Technologies Launches ModusToolbox™ Motor Kit to Simplify Motor Control Development
- STMicroelectronics IO-Link Actuator Board Brings Turnkey Reference Design to Industrial Monitoring and Equipment Manufacturers
- Melexis uses coreless technology to reduce the size of current sensing devices
- Melexis uses coreless technology to reduce the size of current sensing devices
- Vicor high-performance power modules enable the development of low-altitude avionics and EVTOL
- Chuangshi Technology's first appearance at electronica 2024: accelerating the overseas expansion of domestic distributors
- Chuangshi Technology's first appearance at electronica 2024: accelerating the overseas expansion of domestic distributors
- "Cross-chip" quantum entanglement helps build more powerful quantum computing capabilities
- Ultrasound patch can continuously and noninvasively monitor blood pressure
- [N32L43x Review] 5. Get MCU 96-bit UID, 128-bit UCID
- [Popular Science] What are the pulse signal parameters? How can we get the desired pulse signal parameters?
- LED Driver
- Selection of HAL library and STD library
- Reasonable avoidance: Supporting seamless communication and non-interference vehicle-to-everything design
- Configuration example - ModbusTCP to Profinet gateway to connect tightening shaft drive
- Renesas CPK-RA6M4 Development Board Review----I2C
- EK314 Programming Manual
- Serial-to-parallel conversion circuit
- How to read constant array in flash using IAR FOR AVR?