C8051F LCD1602程序

以下资料由微雪电子整理并发布,未经许可不得转载,否则追究相应责任!

/********************************************************************************************************
*
* File : LCD1602.c
* Hardware Environment: DVK501 && F320 EX
* Build Environment : Silicon LABs 3.42.00 / uVision3 V3.80 20100913
* Version :
* By : Su Wei Feng
*
*                                                          (c) Copyright 2005-2010, WaveShare
*                                                                     http://www.waveshare.net
*                                                                         All Rights Reserved
*
*********************************************************************************************************/

#include<c8051f320.h>

#define uchar unsigned char
#define uint unsigned int

sbit lcden=P0^0;
sbit lcdrw=P0^6;
sbit lcdrs=P0^7;

uchar num;

uchar code table[]=" WaveShare";

void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}

void write_com(uchar com)
{
lcdrs=0;
lcdrw=0;
lcden=0;
P1=com;
delay(5);
lcden=1;
delay(5);
lcden=0;
}

void write_data(uchar dat)
{
lcdrs=1;
lcdrw=0;
lcden=0;
P1=dat;
delay(5);
lcden=1;
delay(5);
lcden=0;
}

void init()
{
write_com(0x38);
write_com(0x0c);
write_com(0x06);
P0MDOUT = 0xFF;
P1MDOUT = 0xFF;
}

void display()
{
write_com(0x01);
write_com(0x80);
for(num=0;num<12;num++)
{
write_data(table[num]);
delay(5);
}
}

void main()
{
PCA0MD &= ~0x40; //Clear watchdog timer enable
XBR1 = 0x40;
OSCICN |= 0x03;
delay(100);
init();
display();
while(1);
}


C8051F LCD1602程序

——