带有PIC16F877A的LCD显示屏

时间:2019-03-06 17:46:14

标签: c

我是PIC编程的新手。我被一项任务震惊 当我按特定的开关3次时,会在LCD上显示字母“ A”。如果有人知道,请帮助我。预先感谢。

1 个答案:

答案 0 :(得分:2)

     I used MPLAB X IDE V5.0.





// CONFIG
                    #pragma config FOSC = EXTRC     // Oscillator Selection bits (RC oscillator)
                    #pragma config WDTE = OFF       // Watchdog Timer Enable bit (WDT disabled)
                    #pragma config PWRTE = OFF      // Power-up Timer Enable bit (PWRT disabled)
                    #pragma config BOREN = OFF      // Brown-out Reset Enable bit (BOR disabled)
                    #pragma config LVP = OFF        // Low-Voltage (Single-Supply) In-Circuit Serial Programming Enable bit (RB3 is digital I/O, HV on MCLR must be used for programming)
                    #pragma config CPD = OFF        // Data EEPROM Memory Code Protection bit (Data EEPROM code protection off)
                    #pragma config WRT = OFF        // Flash Program Memory Write Enable bits (Write protection off; all program memory may be written to by EECON control)
                    #pragma config CP = OFF         // Flash Program Memory Code Protection bit (Code protection off)



                #include <xc.h>
                void command(unsigned char cmd);
                void data(unsigned char dat);
                void display_string(const char *s);
                void delay();

            void main(void) {

                TRISB=0X00;
                PORTB=0X00;
                TRISE=0X00;
                PORTE=0X00;
                ADCON1=0X06;// reference the Hyperlink

                command(0x01);//clear display
                delay();
                command(0x0C);//Turn on the display and off cursor blinking
                delay();
                command(0x05);//increment the cursor after byte each byte written
                delay();
                command(0x38);//set 8-bit interface 
                delay();
                command(0x80);//set DRAM address
                delay();

                while(1)
                {
                    command(0x80);//set DRAM address

                    display_string("A"); //display A 
                     data('A'); // or dat like A
                     data(65);  // ASCII key A=65



                }


            }

            void command(unsigned char cmd)
            {
                PORTE=0X04;
                PORTB=cmd;
                delay();
                RE2=0;

            }
            void data(unsigned char dat)
            {
                PORTE=0X05;
                PORTB=data;
                delay();
                RE2=0;

            }

            void display_string(const char *s)
            {
                while(*s)
                    data(*s++);
            }
            void delay()
            {
                for(int i=0;i<255;i++);
            }

Reference