|
Tài trợ cho PIC Vietnam |
Các dự án mã nguồn mở Nếu bạn không mở mã nguồn, ít nhất là một phần nào đó trong dự án của bạn, xin đừng vào đây. |
|
Ðiều Chỉnh | Xếp Bài |
29-09-2011, 10:46 AM | #8 | |
Nhập môn đệ tử
Tham gia ngày: Feb 2009
Bài gửi: 8
: |
Ai kiểm tra giùm hộ tôi với....
Trích:
#include <htc.h> #include "stdio.h" __CONFIG(HS & PWRTEN & BOREN & LVPDIS & WDTDIS ); #define _XTAL_FREQ 20000000 #define data74595 RD1 #define clock74595 RD0 #define latch74595 RD2 #define uchar unsigned char #define bit_set(var,bitno) ((var) |= 1 << (bitno)) #define bit_clear(var,bitno) ((var) &= ~(1 << (bitno))) #define bit_test(data,bitno) ((data>>bitno)&0x01) uchar buffer_data_lcd = 0; void OutPut74595(unsigned char data); void LCD_STROBE() { bit_set(buffer_data_lcd,2); OutPut74595(buffer_data_lcd); bit_clear(buffer_data_lcd,2); OutPut74595(buffer_data_lcd); } /* write a byte to the LCD in 4 bit mode */ void LCD_DATA(unsigned char c) { buffer_data_lcd = buffer_data_lcd & 0x0F; buffer_data_lcd = buffer_data_lcd | (c << 4); OutPut74595(buffer_data_lcd); } void lcd_write(unsigned char c) { __delay_us(40); LCD_DATA(c>>4); LCD_STROBE(); LCD_DATA( c ); LCD_STROBE(); } void lcd_clear(void) { bit_clear(buffer_data_lcd,0); OutPut74595(buffer_data_lcd); lcd_write(0x1); __delay_ms(2); } /* write one character to the LCD */ void lcd_putchar(char c) { bit_set(buffer_data_lcd,0); OutPut74595(buffer_data_lcd); lcd_write( c ); } void lcd_gotoxy(unsigned char row,unsigned char col) { bit_clear(buffer_data_lcd,0); OutPut74595(buffer_data_lcd); switch(row) { case 0 : lcd_write( 0x80 + col ) ; break ; case 1 : lcd_write( 0xC0 + col ) ; break ; case 2 : lcd_write( 0x94 + col ) ; break ; case 3 : lcd_write( 0xD4 + col ) ; break ; }; } /* initialise the LCD - put into 4 bit mode */ void lcd_init() { buffer_data_lcd = 0; OutPut74595(buffer_data_lcd); __delay_ms(15); // wait 15mSec after power applied, LCD_DATA(0x03); LCD_STROBE(); __delay_ms(5); LCD_STROBE(); __delay_us(200); LCD_STROBE(); __delay_us(200); LCD_DATA(2); // Four bit mode LCD_STROBE(); lcd_write(0x28); // Set interface length lcd_write(0x0C); // Display On, Cursor On, Cursor Blink lcd_clear(); // Clear screen lcd_write(0x6); // Set entry Mode } //------------------------------------------------ void OutPut74595(uchar data) { uchar i ; for(i=0;i<8;i++) { if( bit_test(data,7) ) { data74595=1 ; } else { data74595=0 ; }; clock74595=0; clock74595=1; data = data<<1 ; }; //----------------------------- latch74595=1 ; latch74595=0 ; } //------------------------------------------------------------- void main(void) { TRISA=0xFF; TRISB=0x00; TRISC=0xFF; TRISD=0xF0 ; PORTB=0x00; lcd_init(); lcd_gotoxy(1,0); printf(" Hoang Cute"); while( 1 ) { }; } |
|
|
|