立即注册 找回密码

微雪课堂

搜索
微雪课堂 C8051 C8051F单片机笑傲江湖 查看内容

C8051F LCD1602程序

2015-7-13 10:09| 发布者: kaloha| 查看: 5465| 评论: 0

摘要: /********************************************************************************************************** File : LCD1602.c* Hardware Environment: DVK501 F320 EX* Build Environment : Silicon LABs 3. ...

/********************************************************************************************************
*
* 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
*                                                                     https://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);
}

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


439

顶一下

刚表态过的朋友 (439 人)

最新评论

所有教程

微雪官网|产品资料|手机版|小黑屋|微雪课堂. ( 粤ICP备05067009号 )

GMT+8, 2024-11-28 08:02 , Processed in 0.017871 second(s), 20 queries .

返回顶部