【发布时间】:2015-06-15 13:46:21
【问题描述】:
我正在学习如何使用 CCS PCWHD IDE C 编译器对 PIC 控制器进行编程。我正在尝试使用 C 代码在 Proteus 8 的 LCD 显示屏上显示一条消息。
我编写的代码可以编译,生成 .HEX 和 .COF 文件没有问题。但是,当我尝试在 Proteus 8 上模拟此代码时,我看到的只是 LCD 屏幕打开。没有闪烁的光标或文本出现。我反复检查了连接和 Proteus 原理图,但没有发现任何问题。
我正在使用带有 4MHz 外部晶体的 PIC16F877A 微控制器我使用的 LCD 显示器是 LM016L(16x2 LCD 显示器)。我不明白问题出在 Proteus、C 编译器还是我的代码上?
我写的代码如下:
#include <16F877A.h>
#FUSES NOWDT //No Watch Dog Timer
#FUSES XT //Crystal osc <= 4mhz for PCM/PCH , 3mhz to 10 mhz for PCD
#FUSES PUT //Power Up Timer
#FUSES NOPROTECT //Code not protected from reading
#FUSES NODEBUG //No Debug mode for ICD
#FUSES NOBROWNOUT //No brownout reset
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOCPD //No EE protection
#FUSES NOWRT //Program memory not write protected
#use delay(clock=4000000) //4MHz Crystal
#use fast_io(b)
#byte ADCON1=0x9F
//Implementing the LCD onto Port B
#define PORTB=0x06
#define LCD_ENABLE_PIN PIN_B2
#define LCD_RS_PIN PIN_B0
#define LCD_RW_PIN PIN_B1
#define LCD_DATA_PORT PORTB
#define LCD_DATA4 PIN_B4
#define LCD_DATA5 PIN_B5
#define LCD_DATA6 PIN_B6
#define LCD_DATA7 PIN_B7
#define LCD_TYPE 2 //2 Line display
#include <lcd.c> // LCD library
void main()
{
set_tris_b(0x00); //Port B is completely output
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_CLOCK_DIV_2);
setup_psp(PSP_DISABLED);
setup_spi(SPI_SS_DISABLED);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
//TODO: User Code
lcd_init();
delay_ms(10);
while (TRUE)
{
lcd_send_byte(0,0x0e); //Blinking Cursor
delay_ms(10);
printf(lcd_putc,"\fHello");
printf(lcd_putc,"\nWorld");
delay_ms(1000);
printf(lcd_putc,"\fMy");
printf(lcd_putc,"\nFirst");
delay_ms(1000);
lcd_gotoxy(5,1); //Row 1, Column 5
delay_ms(10);
printf(lcd_putc,"\fPIC");
lcd_gotoxy(1,2); //Row 2 column 5
delay_ms(10);
printf(lcd_putc,"Project");
delay_ms(1000);
}
}
【问题讨论】: