?? lcd和定時(shí).txt
字號(hào):
//文件包含
#include <reg51.h>
#include <string.h>
#include <intrins.h>
#include<absacc.h>
#include<math.h>
//宏定義數(shù)據(jù)類型
#define INT8U unsigned char
#define INT16U unsigned int
#define uchar unsigned char
#define uint unsigned int
#define ulong unsigned long
//引腳定義
#define LCD_Data P0
sbit LCD1602_RS = P0^0;
sbit LCD1602_RW = P0^1;
sbit LCD1602_EN = P0^2;
sbit dac0832_cs = P2^3;
//全局變量定義
uchar code ASCII[]={"0123456789ABCDEFnnnnnnnnnnnn"};
uchar testnum=0;
/*************************************液晶顯示*******************************************
*******************************************************************************************
******************************************************************************************/
void delay_nms(unsigned int n)
{
unsigned int i=0,j=0;
for (i=n;i>0;i--)
for (j=0;j<1140;j++);
}
void Delayms(void)
{
uchar TempCycA =5;//10
uint TempCycB;
while(TempCycA--)
{
TempCycB=6269;
while(TempCycB--);
};
}
/******************** LCD PART *************************************/
void LCD_delay(void)
{
unsigned char i;
for(i=40;i>0;i--)
;
}
void LCD_en_command(unsigned char command)
{
LCD1602_RS=0;
LCD1602_RW=0;
LCD1602_EN=0;
LCD_Data |=(command & 0xf0);
LCD_Data &=(command & 0xf0) | 0x0f;
LCD1602_EN=1;
LCD_delay();
LCD1602_EN=0;
LCD_Data |=(command & 0x0f)<<4;
LCD_Data &=(command & 0x0f)<<4 | 0x0f;
LCD1602_EN=1;
LCD_delay();
LCD1602_EN=0;
}
/********************************************************************/
void LCD_en_dat(unsigned char dat)
{
LCD1602_RS=1;
LCD1602_RW=0;
LCD1602_EN=0;
LCD_Data |=(dat & 0xf0);
LCD_Data &=(dat & 0xf0) | 0x0f;
LCD1602_EN=1;
LCD_delay();
LCD1602_EN=0;
LCD_Data |=(dat & 0x0f)<<4;
LCD_Data &=(dat & 0x0f)<<4 | 0x0f;
LCD1602_EN=1;
LCD_delay();
LCD1602_EN=0;
}
/********************************************************************/
void LCD_set_xy( unsigned char x, unsigned char y )
{
unsigned char address;
if (y ==0)
address = 0x80 + x;
else
address = 0xC0 + x;
LCD_en_command(address);
}
/********************************************************************/
void LCD_write_char( unsigned x,unsigned char y,unsigned char dat)
{
LCD_set_xy( x, y );
LCD_en_dat(dat);
}
/********************************************************************/
void LCD_write_string(unsigned char X,unsigned char Y,unsigned char *s)
{
LCD_set_xy( X, Y ); //set address
while (*s) // write character
{
//LCDIO=*s; //嚴(yán)重錯(cuò)誤!!!
LCD_en_dat(*s);
s ++;
}
}
/********************************************************************/
void LCD_init(void)
{
LCD_en_command(0x01);
delay_nms(5);
LCD_en_command(0x01);
delay_nms(5);
LCD_en_command(0x28);
delay_nms(5);
LCD_en_command(0x28);
delay_nms(5);
LCD_en_command(0x28);
delay_nms(5);
LCD_en_command(0x0C);
delay_nms(5);
LCD_en_command(0x80);
delay_nms(5);
LCD_en_command(0x01);
delay_nms(5);
}
/******************************************************************/
/******************************************中斷********************************************
*******************************************************************************************
******************************************************************************************/
void steepdelay(void) interrupt 1
{
TH0=0x00;
TL0=0x00;
TR0=1;
testnum++;
}
/******************************************中斷_結(jié)束********************************************
*******************************************************************************************
**************************************************************************************/
//定時(shí)器初始化
void interruptInit(void)
{
TMOD=0x01;
TH0=0x00;
TL0=0x00;
TR0=1;
ET0=1;
EA=1;
}
/****************************************主程序*******************************************
*******************************************************************************************
*****************************************************************************************/
void main(void)
{
interruptInit();
LCD_init(); //LCM初始化
LCD_write_string(0,0 ," ");
Delayms();
Delayms();
LCD_write_string(0,0 ,"waiting ");
Delayms();
Delayms();
LCD_write_string(0,0 ," ");
Delayms();
Delayms();
LCD_write_string(0,0 ,"welcoming ");
Delayms();
Delayms();
LCD_write_string(0,0 ," ");
Delayms(); LCD_init(); //LCM初始化
while(1)
{
LCD_write_string(0,0 ,"Motor ");
LCD_write_string(0,2 ,"zhaosdfjj ");
LCD_write_char(9,1,ASCII[testnum]);
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -