ATmega16 drives ds12c887 and displays on lcd1602

Publisher:夜色迷离Latest update time:2014-12-04 Source: 21icKeywords:ATmega16  ds12c887  lcd1602 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

#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<  MCUCSR |= 1<DDRA=0XFF;
DDRB=0XFF;
DDRC=0XFF;
  write_com(0X01);
  write_com(0X03);
/////////////////
write_ds(0x0b,0x02);
//key_set();
while(1)
{
ds12887();
disan();
display();
delay(1000);
}
}

Keywords:ATmega16  ds12c887  lcd1602 Reference address:ATmega16 drives ds12c887 and displays on lcd1602

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

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号