如题,在做PIC16F1937段式LCD程序时,不知道怎么回事段式LCD一直点不亮,还请高手帮帮忙,谢谢!
SEG0~SEG9 COM0~COM3
代码如下:
#include <pic16f1937.h>
//-------------------------------------------------------------------------------//
//函数名:Init_Port //
//功能:初始化I/O口 //
//------------------------------------------------------------------------------//
void Init_Port(void)
{
TRISA = 0x00;
TRISB = 0x00;
TRISC = 0x00;
TRISD = 0x00;
TRISE = 0x00;
//////////////
PORTA = 0x00;
PORTB = 0x00;
PORTC = 0x00;
PORTD = 0x00;
PORTE = 0x00;
}
//-------------------------------------------------------------------------------//
//函数名:lcd_init //
//功能:lcd初始化 //
//------------------------------------------------------------------------------//
void lcd_init(void)
{
LCDCON=0b10011111;//
//|||||||+---LMUX0
//||||||+----LMUX1 11--1/4
//|||||+-----CS0 00=FOSC/8192,01 = T1OSC (Timer1) /32,
//||||+-----CS1 1x=LFINTOSC(31 kHz) /32
//|||+------VLCDEN
//||+-------WERR
//|+--------#SLPEN
//+---------LCDEN
LCDPS=0b00110000;//
//|||||||+---LP0 1111 = 1:16
//||||||+----LP1
//|||||+-----LP2
//||||+-----LP3 0000=1:1
//|||+------WA 1 = 允许写入LCDDATAx 寄存器
//||+-------LCDA 1 = 使能LCD 驱动模块
//|+--------BIASMD当LMUX<1:0>=11时:0=1/3偏置模式(不要将该位置1)
//+---------WFT 1在每一帧边界改变相位0在每一公共端类型内改变相位
//LCDREF=0B11101110;
//
LCDSE0=0b11111111;
LCDSE1=0b00000011;//LCD引脚使能寄存器,SEG0~SEG9
}
//-------------------------------------------------------------------------------//
//函数名:main //
//功能:主程序入口函数 //
//------------------------------------------------------------------------------//
void main(void)
{
unsigned char i;
INTCON=0;//关闭总中断,禁止外设,timer0,外部,电平中断,清除timer0,外部,电平中断标志
ANSELA =0x00;
ANSELB =0x00;
//ANSELC =0x00;
ANSELD =0x00;
ANSELE =0x00;
Init_Port();
lcd_init();
LCDDATA0=0xfc;
LCDDATA3=0xfc;
LCDDATA6=0xfc;
LCDDATA9=0xfc;
while(1)
{
LCDDATA0 = 0XFF;
DelayMs(500);
LCDDATA0 = 0X00;
DelayMs(500);
}
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
代码如下:
#include <pic16f1937.h>
//-------------------------------------------------------------------------------//
//函数名:Init_Port      //
//功能:初始化I/O口      //
//------------------------------------------------------------------------------//
void Init_Port(void)
{
TRISA = 0x00;
TRISB = 0x00;
TRISC = 0x00;
TRISD = 0x00;
TRISE = 0x00;
//////////////
PORTA = 0x00; 
PORTB = 0x00;
PORTC = 0x00;
PORTD = 0x00; 
PORTE = 0x00; 
}
//-------------------------------------------------------------------------------//
//函数名:lcd_init     //
//功能:lcd初始化     //
//------------------------------------------------------------------------------//
void lcd_init(void) 
{ 
LCDCON=0b10011111;// 
//|||||||+---LMUX0 
//||||||+----LMUX1 11--1/4
//|||||+-----CS0 00=FOSC/8192,01 = T1OSC (Timer1) /32, 
//||||+-----CS1 1x=LFINTOSC(31 kHz) /32 
//|||+------VLCDEN 
//||+-------WERR 
//|+--------#SLPEN 
//+---------LCDEN 
LCDPS=0b00110000;// 
//|||||||+---LP0 1111 = 1:16 
//||||||+----LP1  
//|||||+-----LP2 
//||||+-----LP3 0000=1:1  
//|||+------WA 1 = 允许写入LCDDATAx 寄存器 
//||+-------LCDA 1 = 使能LCD 驱动模块 
//|+--------BIASMD当LMUX<1:0>=11时:0=1/3偏置模式(不要将该位置1) 
//+---------WFT 1在每一帧边界改变相位0在每一公共端类型内改变相位
LCDREF=0B10101110;
//
LCDSE0=0b11111111; 
LCDSE1=0b00000011;//LCD引脚使能寄存器,SEG0~SEG9
}
//-------------------------------------------------------------------------------//
//函数名:main      //
//功能:主程序入口函数      //
//------------------------------------------------------------------------------//
void main(void)
{
unsigned char i;
Init_Port();
lcd_init();
LCDDATA0=0xfc; 
LCDDATA3=0xfc; 
LCDDATA6=0xfc; 
LCDDATA9=0xfc; 
while(1) 
{
LCDDATA0 = 0XFF;
DelayMs(500);
LCDDATA0 = 0X00;
DelayMs(500);
}
}
=======lcd_hw.c================
#include <htc.h> //we use picc
#include "lcd_hw.h" //we use onboard hardware lcd
//global variable
//initialize the lcd
void lcd_init(void) {
//set up lcdcon
LCDEN = 0; //turn off the lcd
SLPEN = 1; //no lcd drive in sleep mode
VLCDEN = 1; //enable lcd bias voltage
CS1=0, CS0=0; //0b00 -> Fosc / 8192. 0b01 = Timer1/32, 0b1x = LFINTOSC(31khz)/32
LMUX1=(LCD_COM & LCD_COM2) >> 1;
LMUX0=(LCD_COM & LCD_COM1); //0b00 -> static(COM0); 0b01 -> 1/2 (COM0..1); 0b10 -> 1/3 (COM0..2); 0b11 -> 1/4 (COM0..3)
//set up lcdps
WFT = 0; //1=wave form change on the boundary, 0=in between
switch (LCD_COM) {
case LCD_COM0: BIASMD = 0; break; //has to be set to 0
case LCD_COM1: BIASMD = 1; break; //1=1/2 bias. 0=1/3 bias
case LCD_COM2: BIASMD = 0; break; //1=1/3 bias. 0=1/2 bias
case LCD_COM3: BIASMD = 0; break; //has to be set to 0
}
//LCDA=1, WA=1; //set the status bits
//set up the prescaler
LP3=(LCD_PS & 0x08) >> 3;
LP2=(LCD_PS & 0x04) >> 2;
LP1=(LCD_PS & 0x02) >> 1;
LP0=(LCD_PS & 0x01) >> 0; //lcd prescaler. 1:1(0b0000) -> 16:1 (0b1111)
//enable the segments - need customization
LCDSE0 = 0xff; //enable lcd0..7
LCDSE1 = 0xff; //enable lcd8..15
LCDSE2 = 0xff; //enable lcd16..23
//LCDSE3 = 0xff; //enable lcd24..31
//LCDSE4 = 0xff; //enable lcd32..39
//LCDSE5 = 0xff; //enable lcd40..47
//enable the output - set by lcdsex automatically
//TRISA = 0x00; //porta as output
//TRISB = 0x00; //portb as output
//TRISC = 0x00; //portc as output
//TRISD = 0x00; //portd as output
//TRISE = 0x00; //porte as output
LCDEN = 1; //enable the lcd
}
//display data on lcd
void lcd_display(unsigned char * vRAM) {
unsigned char index;
const unsigned char _7seg_font[]={
0x3f, //'0'
0x06, //'1'
0x5b, //'2'
0x4f, //'3'
0x66, //'4'
0x6d, //'5'
0x7d, //'6'
0x07, //'7'
0x7f, //'8'
0x6f, //'9'
0x77, //'A'
0x7c, //'b'
0x39, //'C'
0x5e, //'d'
0x79, //'E'
0x71, //'F'
0x40}; //' '
//set up the data - will need triming
//vRAM[] is numerical
LCDDATA0 = _7seg_font[vRAM[0]];
LCDDATA1 = _7seg_font[vRAM[1]];
LCDDATA2 = _7seg_font[vRAM[2]];
LCDDATA3 = _7seg_font[vRAM[3]];
LCDDATA4 = _7seg_font[vRAM[4]];
LCDDATA5 = _7seg_font[vRAM[5]];
LCDDATA6 = _7seg_font[vRAM[6]];
LCDDATA7 = _7seg_font[vRAM[7]];
LCDDATA8 = _7seg_font[vRAM[8]];
LCDDATA9 = _7seg_font[vRAM[9]];
LCDDATA10 = _7seg_font[vRAM[10]];
LCDDATA11 = _7seg_font[vRAM[11]];
}
============lcd_hw.h=================
//header file for on-board lcd hardware
//hardware configuration
#define LCD_PS LCD_PS1x //lcd prescaler
#define LCD_COM LCD_COM1 //lcd com
//#define LCD_DIGs 8 //number of lcd digits
//end hardware configuration
#define LCD_COM0 0x00 //com0 - static
#define LCD_COM1 0x01 //com0..1 -> 1/2
#define LCD_COM2 0x02 //com0..2 -> 1/3
#define LCD_COM3 0x03 //com0..3 -> 1/4
//prescaler settings
#define LCD_PS1x 0x00
#define LCD_PS2x 0x01
#define LCD_PS3x 0x02
#define LCD_PS4x 0x03
#define LCD_PS5x 0x04
#define LCD_PS6x 0x05
#define LCD_PS7x 0x06
#define LCD_PS8x 0x07
#define LCD_PS9x 0x08
#define LCD_PS10x 0x09
#define LCD_PS11x 0x0a
#define LCD_PS12x 0x0b
#define LCD_PS13x 0x0c
#define LCD_PS14x 0x0d
#define LCD_PS15x 0x0e
#define LCD_PS16x 0x0f
//global variable
//initialize the lcd
void lcd_init(void);
//display data on lcd
//vRAM is an array containing the numerical digits
void lcd_display(unsigned char * vRAM);
一周热门 更多>