![]() |
|
Tài trợ cho PIC Vietnam |
|
Ðiều Chỉnh | Xếp Bài |
![]() |
#1 |
Đệ tử 2 túi
Tham gia ngày: Nov 2006
Bài gửi: 35
: |
Nhờ các bác giúp đỡ chương trình này có gì sai không mà không chạy
- Sử dụng PIC 16F887, kết nối với LCD theo chế độ 4 bít.
- D4====RB0 - D5====RB1 - D6====RB2 - D7====RB3 R/W nối đất R/S=====RB4 E======RB5 /* * File: newmainpicc.c * Author: DINH LUAN * * Created on 01/09, 2013, */ #include "htc.h" #define_XTAL_FREQ 8000000 __CONFIG(FOSC_HS & WDTE_OFF & PWRTE_ON & MCLRE_ON & CP_OFF & BOREN_OFF & IESO_OFF & FCMEN_OFF & LVP_OFF & DEBUG_ON); //1st config. Word __CONFIG(BOR4V_BOR21V); //2st config. #define RS RB4 #define EN RB5 #define LCD_OUT PORTB // delay function void _delay_us (unsigned char us){ while(us--){ asm("nop"); asm("nop"); }; } //================================================== ======================================== void _delay_ms(unsigned char ms){ unsigned char i, j; while(ms--){ for (i = 0; i < 20; i++) for (j = 0; j < 100; j++) asm("nop"); }; } // void LCD_STROBE void LCD_STROBE() { EN=1; ; EN=0; } void LCD_DATA(unsigned char c) { unsigned char temp; RS=1; _delay_us(50); // delay 50us temp=c; // send 4 high bit temp=temp>>4; // LCD_OUT = temp|0x30; // LCD_STROBE(); LCD_OUT=c|0x30; // send 4 low bit LCD_STROBE(); } void LCD_CMD(unsigned char c) { RS =0; unsigned char temp; _delay_us(50); temp=c; temp=temp>>4; LCD_OUT = temp&0x0F; LCD_STROBE(); LCD_OUT = temp&0x0F; LCD_STROBE(); } void clear(void) // Clear dislay { LCD_CMD(0x01); _delay_ms(2); } void LCD_INIT() { TRISB =0; EN=0; RS=0; _delay_ms(100);// delay 100ms waiting for operting LCD LCD_CMD(0x28); // Function set (4 bit mode , 2 line, 5x7 Pixels) LCD_CMD(0x0C); // Display on cursor off LCD_CMD(0x06); // Set entry mode (auto increment of cursor) } void string(const char *q) { while(*q) { LCD_DATA(*q++); } } void main() { LCD_INIT(); // while(1) { LCD_CMD(0x80); string("HELLO"); LCD_CMD(0xc0); string("LCD BIT MODE "); } } |
![]() |
![]() |
|
|