|
发表于 2008-8-20 17:35:15
|
显示全部楼层
按楼主所给的时序图用PIC16F84A 成功驱动 三位LCD
![](http://cache.amobbs.com/bbs_upload782111/files_10/ourdev_384921.jpg)
(原文件名:LCD.jpg)
//引入头文件*********************************************************
#include "delay.h"
#include "delay.c"
#include <pic1684.h>
//字符查表***********************************************************
const unsigned char Lcd[10] = {0x3f, 0x06, 0x5b, 0x4f, 0x66,
0x6d, 0x7d, 0x07, 0x7f, 0x6f};
//*******************************************************************
//函数名称:port_init();
//输入参数:无
//输出参数:无
//功能描述:端口设置
//建造日期:2008.06.03
//*****************************************************************
void PortInit(void)
{
PORTA = 0xff; //A 口设置
PORTB = 0xff; //B 口设置
TRISA = 0x00; //
TRISB = 0x00; //
}
//*******************************************************************
//函数名称:main();
//输入参数:无
//输出参数:无
//功能描述:主要程序
//建造日期:2008.06.03
//*******************************************************************
void main(void) //
{
unsigned char temp[3];
unsigned char i, j;
PortInit(); //脚位设置
temp[0] = Lcd[1];
temp[1] = Lcd[2];
temp[2] = Lcd[3];
while (1)
{
PORTA = 0b11111110; //正亮显示
TRISA = 0b11111110;
PORTB = temp[0];
DelayMs(2);
PORTA = 0b11111000; //关闭显示
TRISA = 0b11111000;
PORTB = 0x00;
DelayMs(2);
PORTA = 0b11111111; //负亮显示
TRISA = 0b11111110;
PORTB = temp[0] ^ 0xff;
DelayMs(2);
PORTA = 0b11111000; //关闭显示
TRISA = 0b11111000;
PORTB = 0x00;
DelayMs(2);
PORTA = 0b11111101; //正亮显示
TRISA = 0b11111101;
PORTB = temp[1];
DelayMs(2);
PORTA = 0b11111000; //关闭显示
TRISA = 0b11111000;
PORTB = 0x00;
DelayMs(2);
PORTA = 0b11111111; //负亮显示
TRISA = 0b11111101;
PORTB = temp[1] ^ 0xff;
DelayMs(2);
PORTA = 0b11111000; //关闭显示
TRISA = 0b11111000;
PORTB = 0x00;
DelayMs(2);
PORTA = 0b11111011; //正亮显示
TRISA = 0b11111011;
PORTB = temp[2];
DelayMs(2);
PORTA = 0b11111000; //关闭显示
TRISA = 0b11111000;
PORTB = 0x00;
DelayMs(2);
PORTA = 0b11111111; //负亮显示
TRISA = 0b11111011;
PORTB = temp[2] ^ 0xff;
DelayMs(2);
PORTA = 0b11111000; //关闭显示
TRISA = 0b11111000;
PORTB = 0x00;
DelayMs(2);
}
} |
|