微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > AVR128的程序——12864液晶与ds1302与ds18b20的综合运用

AVR128的程序——12864液晶与ds1302与ds18b20的综合运用

时间:11-22 来源:互联网 点击:
此程序包含子文件

#include

#include

#include "12864lcd.h"

#include "ds1302.h"

#include "ds18B20.h"

void mcu_init(void)

{

DDRA = 0XFF;

PORTA = 0XFF;

DDRC = 0XFF;

PORTC = 0XFF;

DDRF |= 0X0E;

PORTF |= 0X0E;

PORTF &= 0xF0;

DDRB |= 0X10;

PORTB |= 0X10;

psbset;

rsout;

rwout;

enout;

}

void main(void)

{

uchar i,j;

uint k;

mcu_init();

shi_BCD();

ds1302_init();

ds1302_write_time();

init12864lcd();

display();

display1();

display2();

display3();

while(1)

{

ds1302_read_time();

time_Process();

write_sfm(0x8D,num);

write_sfm(0x8B,fen);

write_sfm(0x89,shi);

write_sfm(0x86,ri);

write_sfm(0x84,yue);

write_sfm(0x92,zhou);

ds1820_reset();

ds1820_write_byte(0xCC);

ds1820_write_byte(0x44);

Delayms(2);

ds1820_reset();

ds1820_write_byte(0xCC);

ds1820_write_byte(0xbe);

i=ds1820_read_byte();

j=ds1820_read_byte();

k=j*256+i; //这里k的值会大于255 所以定义的时候要写成uint型,否则会溢出。

k=k*0.0625;

write_wendu(0x96,k);

}

}

#ifndef __12864LCD_H__

#define __12864LCD_H__

#define uint unsigned int

#define uchar unsigned char

#define psbset DDRB |= (1<4)

#define psbset PORTB |= (1<4)

#define psbclr PORTB &=~(1<4)

#define rsout DDRB |= (1<5)

#define rsset PORTB |=(1<5)

#define rsclr PORTB &=~(1<5)

#define rwout DDRB |= (1<6)

#define rwset PORTB |= (1<6)

#define rwclr PORTB &= ~(1<6)

#define enout DDRB |= (1<7)

#define enset PORTB |= (1<7)

#define enclr PORTB &= ~(1<7)

unsigned char table1[]=" 2012年02月04日";

unsigned char table2[]="星期六 温度 0℃";

unsigned char table3[]=" 00: 00: 00";

unsigned char table4[]=" 科嵌电子创作";

uint num=50,fen=9,shi=8,ri=8,yue=2,zhou=3;

void Delayus(uint US)

{

uint i;

US=US*5/4;

for( i=0;i

}

void Delayms(uint MS)

{

uint i,j;

for( i=0;i

for(j=0;j<1141;j++);

}

void write_12864com(uchar com)

{

rwclr;

rsclr;

Delayus(500);

PORTA=com;

enset;

Delayus(1000);

enclr;

Delayus(1000);

}

void write_12864dat(uchar dat)

{

rwclr;

rsset;

Delayus(500);

PORTA=dat;

enset;

Delayus(1000);

enclr;

Delayus(1000);

}

void init12864lcd(void)

{

Delayms(500);

write_12864com(0x30);

Delayus(500);

write_12864com(0x30);

Delayus(500);

write_12864com(0x0f);

Delayus(500);

write_12864com(0x01);

Delayms(25);

write_12864com(0x06);

Delayus(2500);

write_12864com(0x0c);

Delayus(500);

}

void display(void)

{

uchar i;

write_12864com(0x80);

for(i=0;i<16;i++)

{

write_12864dat(table1[i]);

Delayms(10);

}

}

void display1(void)

{

uchar i;

write_12864com(0x90);

for(i=0;i<16;i++)

{

write_12864dat(table2[i]);

Delayms(10);

}

}

void display2(void)

{

uchar i;

write_12864com(0x88);

for(i=0;i<12;i++)

{

write_12864dat(table3[i]);

Delayms(10);

}

}

void display3(void)

{

uchar i;

write_12864com(0x98);

for(i=0;i<14;i++)

{

write_12864dat(table4[i]);

Delayms(10);

}

}

void write_sfm(uchar add,uchar date)

{

uchar shi,ge;

shi=date/10;

ge=date;

write_12864com(add);

write_12864dat(0x30+shi);

write_12864dat(0x30+ge);

}

void write_wendu(uchar add,uchar date)

{

uchar shi,ge;

shi=date/10;

ge=date;

write_12864com(add);

write_12864dat(0x30+shi);

write_12864dat(0x30+ge);

}

#endif

#ifndef __DS1302_H__

#define __DS1302_H__

#define uchar unsigned char

#define uint unsigned int

#define ds1302_rst PE4 //定义1302的RST接在PE4

#define ds1302_io PE3 //定义1302的IO接在PE3

#define ds1302_sclk PE2 //定义1302的时钟接在PE2

#define set_ds1302_rst_ddr() DDRE|=1 //复位端置为输出

#define set_ds1302_rst() PORTE|=1 //复位端置1

#define clr_ds1302_rst() PORTE&=~(1 //复位端清0

#define set_ds1302_io_ddr() DDRE|=1 //数据端置为输出

#define set_ds1302_io() PORTE|=1 //数据端置1

#define clr_ds1302_io() PORTE&=~(1 //数据端清0

#define clr_ds1302_io_ddr() DDRE&=~(1 //数据端置为输入

#define in_ds1302_io() PINE&(1 //数据端输入数据

#define set_ds1302_sclk_ddr() DDRE|=1 //时钟端置为输出

#define set_ds1302_sclk() PORTE|=1 //时钟端置1

#define clr_ds1302_sclk() PORTE &=~(1//时钟端清0

#define ds1302_sec_add 0x80 //秒数据地址

#define ds1302_min_add

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top