View Single Post
Old 30-05-2009, 12:31 PM   #3
Mr.Bi
Đệ tử 7 túi
 
Tham gia ngày: Jul 2007
Nơi Cư Ngụ: Đà Nẵng
Bài gửi: 188
:
I> LCD : LCD ở đây t chỉ đưa ra giao tiếp 8 bit cho ng mới dễ tiếp cận . Vì giao tiếp 8 bit nên sẽ cần 8 chân của VDK , do đó t thu gọn = con 74164 --> chỉ dùng 4 chân VDK (E,RS,RX1,TX1) .


Code giao tiếp LCD8bit , dùng 164
Code:
#include <18F4331.h>
#fuses  XT,NOWDT,NOPROTECT,NOLVP,NOBROWNOUT,NOPUT,NOCPD,NODEBUG,NOFCMEN,NOCPB,NOPWMPIN,HPOL_LOW,STVREN
#use    delay(clock=4000000)

#use fast_io(a)
#use fast_io(b)
#use fast_io(c)
#use fast_io(d)
#use fast_io(e)

//=========== LCD ==============
#bit RX1  =0xF80.3 // RA3
#bit TX1  =0xF80.2 // RA2
#bit RS  =0xF82.0  // RC0
#bit E   =0xF84.0  // RE0
void shiftLCD(int8 k)
{ int8 i;
  for(i=8;i>0;i=i-1)
     { if(!bit_test(k,i-1))RX1=0;
       else RX1=1;
       TX1=1;delay_us(20);TX1=0;
     };
 E=1;delay_ms(1);E=0;delay_ms(1);
}
void LCD_PutCmd(int8 k)
{ RS=0;shiftLCD(k);}
void LCD_PutChar(int8 k)
{ RS=1;shiftLCD(k);}
void LCD_Init()
{  delay_ms(100);
   LCD_PutCmd(0x38);
   LCD_PutCmd(0x06); // dich con tro sang phai
   LCD_PutCmd(0x0C); // bat hien thi ,tat con tro
   LCD_PutCmd(0x01); // xoa man hinh
   LCD_PutCmd(0x02); // ve dau dong
   LCD_PutCmd(0x86);
   LCD_PutChar('R');LCD_PutChar('e');LCD_PutChar('a');LCD_PutChar('d');LCD_PutChar('y');
   
}
//+++++++++++++++++++++++++++++++++++

main()
{ 
  TRISA = 0x03;PORTA=0xFF;
  TRISB = 0x00;PORTB=0xFF;
  TRISC = 0xF8;PORTC=0xFF;
  TRISD = 0x0F;PORTD=0xFF;
  TRISE = 0x06;PORTE=0xFF;
  
  LCD_Init();while(1);
}

Hơ hơ mệt wa , nghe music tí đã
Mr.Bi vẫn chưa có mặt trong diễn đàn   Trả Lời Với Trích Dẫn