我正在学习如何使用CCS PCWHD IDE C编译器编程PIC控制器。我试图用C代码在Proteus 8液晶显示器上显示一条消息。
我编写的代码编译并生成.HEX和.COF文件,没有问题。然而,当我试图在Proteus 8上模拟这段代码时,我看到的只是液晶屏幕打开。没有闪烁的光标或文本出现。我已经仔细检查了连接和Proteus的原理图,但没有发现任何问题。
我使用的是带有4 4MHz外部晶体的PIC16F877A微控制器,我使用的液晶显示器是LM016L (16x2液晶显示器)。我不明白问题是与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);
}
} 发布于 2015-06-16 17:08:31
OSCCON),这在给定的代码中是不存在的.ADC,所以您使用了setup_adc_ports(NO_ANALOGS);
因此,下一个setup_adc(ADC_CLOCK_DIV_2);代码行并不是必需的。ground。请查看下面的图像中的连接:

这个链接有Micro C中的代码,供您参考
https://stackoverflow.com/questions/30846836
复制相似问题