-
/*
*
turangwenshiduchuanganqi1.c
*
* Created: 2015/8/5 9:18:56
* Author: Administrator
*/
/**********
**************************************************
************/
/*
常用头文件及宏定义
*/
/********************
**************************************************
**/
#include
#include
//
延时文件
#include
//
睡眠文件
#include
//
中断文件
#include
//eeprom
#define
BIT(x) (1<<(x))
#define uchar unsigned
char
#define uint unsigned int
/**************************
**********************************************/
/* 1602
*/
/***********************************
*************************************/
/*
8
位总线模式
*/
/*
引脚说明
*/
/* PC 0 RS
PC 1 RW PC 2 E PC 3
背光
PB
0
~
PB 7
数据
*/
/*
宏定义
*/
#define DDR_SHUJU DDRB
#define PORT_SHUJU PORTB
#define PIN_SHUJU PINB
#define DDR_KZ DDRC
#define
PORT_KZ PORTC
#define RS_H
PORT_KZ|=BIT(0)
#define RS_L
PORT_KZ&=~(BIT(0))
#define RW_H
PORT_KZ|=BIT(1)
#define RW_L
PORT_KZ&=~(BIT(1))
#define E_H
PORT_KZ|=BIT(2)
#define E_L
PORT_KZ&=~(BIT(2))
#define BEIGUABG_H
PORT_KZ|=BIT(3)
#define BEIGUABG_L
PORT_KZ&=~(BIT(3))
uchar
lcd_read()
//
读忙函数
{
uchar bl;
DDR_SHUJU=0;
//
输入
PORT_SHUJU=0xff;
//
上拉电阻
RS_L;
RW_H;
E_H;
_delay_ms(1);
bl=PIN_SHUJU;
E_L;
RW_L;
PORT_SHUJU=0;
DDR_SHUJU=0xff;
return bl;
}
void
lcd_write_char(uchar shuju)
//
写字符函数
{
while(lcd_read()&BIT(7));
RS_H;
RW_L;
PORT_SHUJU=shuju;
E_H;
E_L;
RS_L;
}
void lcd_write_string(char
*str)
//
写字符串函数
{
while(*str!='0')
{
lcd_write_char(*str);
str++;
}
}
void
lcd_write_zhiling(uchar zhiling)
{
while(lcd_read()&BIT(7));
RS_L;
RW_L;
PORT_SHUJU=zhiling;
E_H;
-
-
-
-
-
-
-
-
-
上一篇:微机原理期末考试复习
下一篇:PID方式控温实例