![]() |
![]() |
#10 |
Đệ tử 1 túi
Tham gia ngày: Apr 2006
Bài gửi: 16
: |
Chương trình gửi ký tự ra 2x16 LCD dùng CCS C
Chương trình gửi ký tự ra 2x16 LCD dùng CCS C
#include "16F877A.h" // PIC16F877A header file #use delay(clock=4000000) // for 4Mhz crystal #fuses XT, NOWDT, NOPROTECT, NOLVP // for debug mode #define WRITE_DATA 0 #define WRITE_COMMAND 1 #define NCHAR_PER_LINE 16 // max char numbers per line #define MS10 10 // 10 milliseconds #define US400 400 // 400 microseconds #define LCD_RS PIN_A1 #define LCD_RW PIN_A2 #define LCD_E PIN_A3 /////////////////////////////////////////////////////////// // /* private */ void lcd_write(byte dat, int1 option) { delay_us(US400); if (option == WRITE_DATA) output_high(LCD_RS); else // option == WRITE_COMMAND output_low(LCD_RS); output_low(LCD_RW); output_b(dat); output_high(LCD_E); delay_us(US400); output_low(LCD_E); } /////////////////////////////////////////////////////////// // void lcd_init(void) { output_low(LCD_E); // Let LCD E line low lcd_write(0x38, WRITE_COMMAND); // Set LCD 16x2, 5x7, 8bits data delay_ms(15); lcd_write(0x01, WRITE_COMMAND); // Clear LCD display delay_ms(MS10); lcd_write(0x0f, WRITE_COMMAND); // Open display & current delay_ms(MS10); lcd_write(0x06, WRITE_COMMAND); // Window fixed (Character Entry Mode?) delay_ms(MS10); } /////////////////////////////////////////////////////////// // void lcd_display_char(int8 line, int8 pos, char ch) { line = (line == 0) ? 0 : 1; pos = (pos > NCHAR_PER_LINE) ? NCHAR_PER_LINE : pos; lcd_write(0x80 + 0x40 * line + pos, WRITE_COMMAND); lcd_write(ch, WRITE_DATA); } /////////////////////////////////////////////////////////// void lcd_display_str(int8 line, char str[], int8 nchars) { int8 i; for (i = 0; i < nchars; i++) lcd_display_char(line, i, str[i]); } /////////////////////////////////////////////////////////// /** * Display characters to a 2x16 LCD * * (1) LCD1 to GND * (2) LCD2 to VDD 5 volts * (3) LCD4 (RS) - LCD5 (RW) - LCD6 (E) to A1, A2, A3 * (4) LCD7-LCD14 to B0-B7 (bus data) * * Ref: http://pic16.com/bbs/dispbbs.asp?boa...ID=5879&page=1 */ void main(void) { int8 i; char LINE1[] = { "SGN Tech" }; char LINE2[] = { "Xin chao" }; lcd_init(); // use of lcd_display_char() for (i = 0; i < 8; i++) lcd_display_char(0, i, LINE1[i]); // use of lcd_display_str lcd_display_str(1, LINE2, 8); } |
![]() |
|
|
![]() |
||||
Ðề tài | Người gửi | Chuyên mục | Trả lời | Bài mới |
TUT về USART trong PIC16F877A | mafd_47a | MPASM | 16 | 19-02-2025 05:32 AM |
TUT ve I2C ( pic16f877a ) | mafd_47a | MPASM | 28 | 28-01-2025 10:45 PM |
Lập nhóm PIC16F877A | nhh | Cơ bản về vi điều khiển và PIC | 285 | 08-03-2017 11:08 PM |
Bộ so sánh và PWM cho PIC16F877A | anhquangngai | Cơ bản về vi điều khiển và PIC | 24 | 08-09-2012 09:00 AM |
Pic16f877a TỪ DỄ TỚi KhÓ | ntc | Cơ bản về vi điều khiển và PIC | 373 | 23-05-2009 10:24 PM |