|
Tài trợ cho PIC Vietnam |
Cơ bản về vi điều khiển và PIC Những bài hướng dẫn cơ bản nhất để làm quen với vi điều khiển PIC |
|
Ðiều Chỉnh | Xếp Bài |
21-11-2012, 03:13 AM | #1 |
Nhập môn đệ tử
Tham gia ngày: Oct 2012
Bài gửi: 8
: |
LCD với PIC18f4550
mình mới chuyển qua PIC18f, sau khi tham khảo chán chê mê mỏi các topic thì mình viết 1 đoạn code hiển thị lcd, tuy nhiên khi mô phỏng trên proteus thì ko thấy chạy, mình viết bằng C18, mong mọi người giúp đỡ
#include <p18cxxx.h> #include<delays.h> #include<xlcd1.h> #include<xlcd1.c> #pragma config PWRT = ON,BOR = OFF,WDT = OFF,PBADEN = OFF unsigned char FullName[] ="NGUYEN TIEN TRIEN"; unsigned char Birthday[]="Date:22/02/1991"; ////////////////// void main(void) { unsigned char config = 0xFF,i=0,addr=0,data=0; ADCON1 = 0xFF; config = EIGHT_BIT & LINES_5X7; PORTA=0; PORTB=0; //******** cau hinh LCD 8bit va ma tran hien thi 5x7 ********************************* OpenXLCD(config); while(BusyXLCD()); //cho cho toi khi LCD het ban //*********** HIEN THI ******** while (1) { WriteCmdXLCD(0x06); SetDDRamAddr(0x00); //80 while(BusyXLCD()); //cho ban putsXLCD(FullName); //hien thi FullName while(BusyXLCD()); //cho ban SetDDRamAddr(0xC0); //hien thi bat dau o dong thu 2 while(BusyXLCD()); //cho ban putsXLCD(Birthday); //hien thi Birthday while(BusyXLCD()); //cho ban Delay10KTCYx(1000); } } đây là file xlcd1.h #ifndef __XLCD1_H #define __XLCD1_H /* PIC18 XLCD peripheral routines. * * >>>>>>>>>>> MODIFIED BY DWD FOR THE PICDEM 2 PLUS LCD SETUP * * Notes: * - These libraries routines are written to support the * Hitachi HD44780 LCD controller. * - The user must define the following items: * - The LCD interface type (4- or 8-bits) * - If 4-bit mode * - whether using the upper or lower nibble * - The data port * - The tris register for data port * - The control signal ports and pins * - The control signal port tris and pins * - The user must provide three delay routines: * - DelayFor18TCY() provides a 18 Tcy delay * - DelayPORXLCD() provides at least 15ms delay * - DelayXLCD() provides at least 5ms delay */ /* Interface type 8-bit or 4-bit * For 8-bit operation uncomment the #define BIT8 */ /* #define BIT8 */ /* When in 4-bit interface define if the data is in the upper * or lower nibble. For lower nibble, comment the #define UPPER */ /* #define UPPER */ /* DATA_PORT defines the port to which the LCD data lines are connected */ /* FOR PICDEM 2 PLUS - USE PORTB */ #define DATA_PORT PORTB #define TRIS_DATA_PORT TRISB /* CTRL_PORT defines the port where the control lines are connected. * These are just samples, change to match your application. */ /* FOR PICDEM 2 PLUS - USE PORTA */ #define RW_PIN LATAbits.LATA1 /* PORT for RW */ #define TRIS_RW TRISAbits.TRISA1 /* TRIS for RW */ #define RS_PIN LATAbits.LATA2 /* PORT for RS */ #define TRIS_RS TRISAbits.TRISA2 /* TRIS for RS */ #define E_PIN LATAbits.LATA0 /* PORT for E */ #define TRIS_E TRISAbits.TRISA0 /* TRIS for E */ /* Adjustment of XLCD Violin*/ /* Display ON/OFF Control defines */ #define DON 0b00001111 /* Display on */ #define DOFF 0b00001011 /* Display off */ #define CURSOR_ON 0b00001111 /* Cursor on */ #define CURSOR_OFF 0b00001101 /* Cursor off */ #define BLINK_ON 0b00001111 /* Cursor Blink */ #define BLINK_OFF 0b00001110 /* Cursor No Blink */ /* Cursor or Display Shift defines */ #define SHIFT_CUR_LEFT 0b00010000 /* Cursor shifts to the left */ #define SHIFT_CUR_RIGHT 0b00010100 /* Cursor shifts to the right */ #define SHIFT_DISP_LEFT 0b00011000 /* Display shifts to the left */ #define SHIFT_DISP_RIGHT 0b00011100 /* Display shifts to the right */ /* Function Set defines */ #define FOUR_BIT 0b00101100 /* 4-bit Interface */ #define EIGHT_BIT 0b00111100 /* 8-bit Interface */ #define LINE_5X7 0b00110000 /* 5x7 characters, single line */ #define LINE_5X10 0b00110100 /* 5x10 characters, single line */ #define LINES_5X7 0b00111000 /* 5x7 characters, multiple line */ #define LINES_5X10 0b00111100 /* 5x10 characters */ #define PARAM_SCLASS auto #define MEM_MODEL far /* Change this to near for small memory model */ #endif |
Tags |
lcd, pic18f4550 |
|
|