英锐恩单片机论坛,Microchip单片机,模拟器件,接口电路,麦肯单片机,单片机应用交流
标题:
PIC16F946的内置液晶显示(LCD)模块驱动及简单显示C程
[打印本页]
作者:
winnie
时间:
2009-4-26 12:39
标题:
PIC16F946的内置液晶显示(LCD)模块驱动及简单显示C程
PIC16F946 除了内置LCD模块, 还具有更低的功耗和丰富的外设,可有效降低许多消费类应用的整体系统成本。集成了LCD模块的新款PIC16F946可广泛应用于:汽车(仪表盘显示屏)、测量仪器(医疗仪器/监视器、读表器、手持终端或远程读取设备)、家用电器 (炉具/烤箱/微波炉的显示屏和控制器)、工业领域(付费系统、水表/气表/电表/热表和燃油泵)、消费类(通用遥控器、可编程恒温器或控制器、灌溉系统控制器、家居安防系统和运动器械)及通讯设备(手机显示屏)等。
以下代码可以帮助大家很好理解 PIC16F946 以及 PIC16F91X系列 的内置LCD模块LCD使用.
LCD及真值表
[attach]702[/attach]
Compiled using PICC 9.50
#include "pic.h"
//函数声明
void Init946();//初始化946
void InitLcd();//初始化LCD寄存器
void UpdateLCD(void);//显示LCD
//
unsigned index,segment;
void main()
{
Init946(); // Initialize the PIC16C946
InitLcd();
UpdateLCD();
while(1)
{
;
}
}
void Init946() // Initialize the PIC16C914
{
PORTA = 0; // Clear ports A,B,C
PORTB = 0;
PORTC = 0;
PORTD = 0;
TRISA = 0; // All RA are digital outputs
TRISB = 0;
TRISC = 0;
TRISD = 0;
ADCON1 =0x07; // RA are digital
GIE = 0; // Enable global interrupts
}
void InitLcd()
{
WFT=0; //A波型
//帧时钟予分频比
LP0=1;
LP1=1;
LP2=0;
LP3=0;
//引脚配置段驱动
LCDSE0=0XFF;
LCDSE1=0XFF;
LCDSE2=0XFF;
//配置休眠模式
SLPEN=0; //休眠模式下使能LCD模块
//写像数全亮
LCDDATA0=0xFF;
LCDDATA1=0xFF;
LCDDATA2=0xFF;
LCDDATA3=0xFF;
LCDDATA4=0xFF;
LCDDATA5=0xFF;
LCDDATA6=0xFF;
LCDDATA7=0xFF;
LCDDATA8=0xFF;
LCDDATA9=0xFF;
LCDDATA10=0xFF;
LCDDATA11=0xFF;
LCDDATA12=0xFF;
LCDDATA13=0xFF;
LCDDATA14=0xFF;
LCDDATA15=0xFF;
//清LCD中断标记位
VLCDEN=0;//引脚
//复用和偏置模式
LMUX0=1;
LMUX1=1; //1/4复用
BIASMD=0; //1/3偏置
//配置时钟源
CS0=0;
CS1=1; //WDT31KHZ/32
//使能偏置电压引脚
VLCDEN=1;//使能引脚
//使能LCD模块
//LCDA=1; //工作状态位使能LCD驱动模块
LCDEN=1; //驱动使能位使能LCD驱动模块
}
void UpdateLCD(void)
{
// Array of 7-segment numbers
// gfedcba
const unsigned char SevenSegTable[16]={ 0b00111111, // 0
0b00000110, // 1
0b01011011, // 2
0b01001111, // 3
0b01100110, // 4
0b01101101, // 5
0b01111101, // 6
0b00000111, // 7
0b01111111, // 8
0b01101111, // 9
0b01110111, // A
0b01111100, // B
0b01011000, // C
0b01011110, // D
0b01111001, // E
0b01110001};// F
// clear all LCD data RAM
LCDDATA0=0;
LCDDATA1=0;
LCDDATA2=0;
LCDDATA3=0;
LCDDATA4=0;
LCDDATA5=0;
LCDDATA6=0;
LCDDATA7=0;
LCDDATA8=0;
LCDDATA9=0;
LCDDATA10=0;
LCDDATA11=0;
LCDDATA12=0;
LCDDATA13=0;
LCDDATA14=0;
LCDDATA15=0;
// Sunday
LCDDATA0 = LCDDATA0|0x01;
// Monday
LCDDATA0 = LCDDATA0|0x02;
// Tuesday
LCDDATA0 = LCDDATA0|0x04;
// Wednesday
LCDDATA0 = LCDDATA0|0x08;
// Thursday
LCDDATA1 = LCDDATA1|0x01;
// Friday
LCDDATA0 = LCDDATA0|0x10;
// Saturday
LCDDATA0 = LCDDATA0|0x20;
// Digit 1
LCDDATA11 = LCDDATA11|0x01;
// Digit 2
index = 2;
segment = SevenSegTable[index];
if(segment&0x01) // D2.a
LCDDATA13 = LCDDATA13|0x08;
if(segment&0x02) // D2.b
LCDDATA12 = LCDDATA12|0x02;
if(segment&0x04) // D2.c
LCDDATA5 = LCDDATA5|0x08;
if(segment&0x08) // D2.d
LCDDATA1 = LCDDATA1|0x08;
if(segment&0x10) // D2.e
LCDDATA4 = LCDDATA4|0x01;
if(segment&0x20) // D2.f
LCDDATA8 = LCDDATA8|0x01;
if(segment&0x40) // D2.g
LCDDATA9 = LCDDATA9|0x08;
// Digit 3
index = 3;
segment = SevenSegTable[index];
if(segment&0x01) // D3.a
LCDDATA13 = LCDDATA13|0x04;
if(segment&0x02) // D3.b
LCDDATA8 = LCDDATA8|0x04;
if(segment&0x04) // D3.c
LCDDATA4 = LCDDATA4|0x04;
if(segment&0x08) // D3.d
LCDDATA1 = LCDDATA1|0x04;
if(segment&0x10) // D3.e
LCDDATA4 = LCDDATA4|0x02;
if(segment&0x20) // D3.f
LCDDATA9 = LCDDATA9|0x04;
if(segment&0x40) // D3.g
LCDDATA5 = LCDDATA5|0x04;
// Digit 4
index = 4;
segment = SevenSegTable[index];
if(segment&0x01) // D4.a
LCDDATA13 = LCDDATA13|0x02;
if(segment&0x02) // D4.b
LCDDATA8 = LCDDATA8|0x08;
if(segment&0x04) // D4.c
LCDDATA4 = LCDDATA4|0x08;
if(segment&0x08) // D4.d
LCDDATA1 = LCDDATA1|0x02;
if(segment&0x10) // D4.e
LCDDATA5 = LCDDATA5|0x02;
if(segment&0x20) // D4.f
LCDDATA12 = LCDDATA12|0x04;
if(segment&0x40) // D4.g
LCDDATA9 = LCDDATA9|0x02;
// Digit 5
index = 5;
segment = SevenSegTable[index];
if(segment&0x01) // D5.a
LCDDATA12 = LCDDATA12|0x80;
if(segment&0x02) // D5.b
LCDDATA12 = LCDDATA12|0x10;
if(segment&0x04) // D5.c
LCDDATA4 = LCDDATA4|0x10;
if(segment&0x08) // D5.d
LCDDATA0 = LCDDATA0|0x80;
if(segment&0x10) // D5.e
LCDDATA4 = LCDDATA4|0x80;
if(segment&0x20) // D5.f
LCDDATA13 = LCDDATA13|0x01;
if(segment&0x40) // D5.g
LCDDATA8 = LCDDATA8|0x80;
// Digit 6
index = 6;
segment = SevenSegTable[index];
if(segment&0x01) // D6.a
LCDDATA12 = LCDDATA12|0x40;
if(segment&0x02) // D6.b
LCDDATA8 = LCDDATA8|0x20;
if(segment&0x04) // D6.c
LCDDATA4 = LCDDATA4|0x20;
if(segment&0x08) // D6.d
LCDDATA0 = LCDDATA0|0x40;
if(segment&0x10) // D6.e
LCDDATA4 = LCDDATA4|0x40;
if(segment&0x20) // D6.f
LCDDATA8 = LCDDATA8|0x10;
if(segment&0x40) // D6.g
LCDDATA8 = LCDDATA8|0x40;
}
欢迎光临 英锐恩单片机论坛,Microchip单片机,模拟器件,接口电路,麦肯单片机,单片机应用交流 (http://enroobbs.com/)
Powered by Discuz! X3.2