#include<reg51.h> // 包含51单片机寄存器定义的头文件 #include<intrins.h> typedef unsigned int uint16; typedef unsigned char uint8; void dispay(); sbit duan=P2^6; sbit wei=P2^7; sbit wr=P1^4; sbit lcden=P1^5; sbit rs=P1^3; void write_12864dat(uint8 dat); void write_12864com(uint8 com); void init(); uint8 code table[]="我是单片机初学者"; void delay_50us(uint16 z) // 11.0592MHz 晶振延时50us { uint16 j,x; for(j=20; j>0; j--) for(x=z;x>0;x--) ; } void delayms(uint16 m) // 11.0592MHz 晶振ms延时,偏差小于1% { uint16 i, j; for(i=m; i>0; i--) for(j=114; j>0; j--); } void main() { P1=0XFF; duan=0; wei=0; init(); dispay(); while(1); } void dispay() { uint8 j; // for(i=0;i<12;i++) // { // a=0x50;//table; // } write_12864com(0x98); delay_50us(1); for(j=0;j<16;j++) { write_12864dat(table[j]); delay_50us(1); // a++; } } void write_12864com(uint8 com) { rs=0; wr=0; lcden=0; delay_50us(1); lcden=1; P0=com; delay_50us(10); lcden=0; delay_50us(2); } void write_12864dat(uint8 dat) { rs=1; wr=0; lcden=0; delay_50us(1); lcden=1; P0=dat; delay_50us(10); lcden=0; delay_50us(2); } void init() { delayms(40); write_12864com(0x30); delay_50us(4); write_12864com(0x30); delay_50us(4); write_12864com(0x0c); delay_50us(4); write_12864com(0x01); delayms(20); write_12864com(0x06); delay_50us(1); } 今天刚刚学的呵呵,初学,献丑了
|