denetleyicini 3 pinini kullanarak lcd kullanma
74hc595 entegresi kullanıldı
denetleyici 16f877a kullanıldı
lcd74hc595.c içinde ayarları değiştirebilirsiniz.
#include<16f877a.h>
#fuses hs
#use delay (clock=20m)
#define SH_CP_CLOCK pin_d0
#define ST_CP__ENABLE pin_d1
#define DS_DATA pin_d2
#define LCD_RS Q2
#define LCD_E Q3
#define LCD_DB4 Q4
#define LCD_DB5 Q5
#define LCD_DB6 Q6
#define LCD_DB7 Q7
#include<LCD_74HC595.c>
const char grafik[8]={
0B00000,
0B00000,
0B11111,
0B10001,
0B10001,
0B11111,
0B00000,
0B00000
};
int i;
void main()
{
lcd_init();
CGRAM_x(0);
for(i=0;i<=7;i++)
lcd_send_byte(1,grafik[i]);
while(true)
{
lcd_gotoxy(1,1);
CGRAM(0);
lcd_putc(" Merhaba");
lcd_gotoxy(5,2);
lcd_putc("sifirzero");
lcd_gotoxy(1,2);
CGRAM(0);
}
}
Aşağıdaki kodlar 74hc595 lcd için hazırlanmış kütüphane kodları kodları kopyalayıp not defterine yapıştırıp sonra kaydederken dosyadı verin .h ile kaydedin.
--------------
/*
sifirzero.blogspot.com
*/
/*
#define SH_CP_CLOCK PIN_D0
#define ST_CP__ENABLE PIN_D1
#define DS_DATA PIN_D2
#define LCD_RS Q1
#define LCD_RW Q2 //opcional GND
#define LCD_E Q3
#define LCD_DB4 Q4
#define LCD_DB5 Q5
#define LCD_DB6 Q6
#define LCD_DB7 Q7
***********************************************************
********************
***********************************************************
********************
Const char Letra1[8]=
{0b11011,0b11011,0b00000,0b11111,0b10001,0b10001,0b01110,0b
00000};
lcd_init(); // Para iniciar el LCD, se declara
antes de su utilizacion
lcd_gotoxy(columna, fila) // lcd_gotoxy(1,1); primera
posicion de la fila 1, lcd_gotoxy(2,1) segunda posicion de
la fila 2
lcd_putc("Mensaje");
Claer_LCS(); // Borra la LCD
CGRAM_x(n); // Donde n es la posicion en
donde se escribiran los caracteres, va de 0 a 7
for(i=0;i<=7 ;i++) lcd_send_byte(1,Letra1[i]); // E
una vez definido la funcion, envia lo 8bytes,
CGRAM(0); // Muestra el caracter especial almacenado
en la posicion 0;
*/
#define Q0 1
#define Q1 2
#define Q2 4
#define Q3 8
#define Q4 16
#define Q5 32
#define Q6 64
#define Q7 128
#define LCD_LINE_1_ADDRESS 0x00
#define LCD_LINE_2_ADDRESS 0x40
#define LCD_LINE_3_ADDRESS 0x14
#define LCD_LINE_4_ADDRESS 0x54
void Register_Write(char dato){
char i;
output_low(SH_CP_CLOCK );
output_low(ST_CP__ENABLE);
for(i=0;i<8;++i) { // Clock out bits from the eo
array
if(bit_test(dato,7-i)==0)
output_low(DS_DATA);
else
output_high(DS_DATA);
output_high(SH_CP_CLOCK);
output_low(SH_CP_CLOCK);
}
output_high(ST_CP__ENABLE);
output_low(ST_CP__ENABLE);
}
void Send_D7_D4(int8 address,int8 nibble)
{
char datos;
if((nibble & 1)==1) datos= datos|LCD_DB4; else datos =
datos&~LCD_DB4;
if((nibble & 2)==2) datos= datos|LCD_DB5; else datos =
datos&~LCD_DB5;
if((nibble & 4)==4) datos= datos|LCD_DB6; else datos =
datos&~LCD_DB6;
if((nibble & 8)==8) datos= datos|LCD_DB7; else datos =
datos&~LCD_DB7;
delay_us(60);
if(address)
datos= datos |LCD_RS;
else
datos = datos &~LCD_RS;
Register_Write( datos | LCD_E);
delay_us(2);
Register_Write( datos & ~LCD_E);
}
void lcd_send_byte(int8 address, int8 n)
{
Send_D7_D4(address,n >> 4);
Send_D7_D4(address,n & 0xf);
}
void lcd_init(void)
{
int8 i;
output_low(ST_CP__ENABLE);
output_low(SH_CP_CLOCK);
output_low(DS_DATA);
delay_ms(15);
for(i=0 ;i < 3; i++)
{
Send_D7_D4(0,0x03);
delay_ms(5);
}
Send_D7_D4(0,0x02);
lcd_send_byte(0, 0x28);
delay_ms(5);
lcd_send_byte(0, 0x08);
delay_ms(5);
lcd_send_byte(0, 0x01);
delay_ms(5);
lcd_send_byte(0, 0x06);
delay_ms(5);
lcd_send_byte(0, 0x0C);
}
void lcd_gotoxy(int8 x, int8 y)
{
int8 address;
switch(y)
{
case 1:
address = LCD_LINE_1_ADDRESS;
break;
case 2:
address = LCD_LINE_2_ADDRESS;
break;
case 3:
address = LCD_LINE_3_ADDRESS;
break;
case 4:
address = LCD_LINE_4_ADDRESS;
break;
default:
address = LCD_LINE_1_ADDRESS;
break;
}
address += x-1;
lcd_send_byte(0, 0x80 | address);
}
void lcd_putc(char c)
{
switch(c)
{
case '\f':
lcd_send_byte(0,1);
delay_ms(2);
break;
case '\n':
lcd_gotoxy(1,2);
break;
default:
lcd_send_byte(1,c);
break;
}
}
void Clear_LCD(){
lcd_send_byte(0,1);
delay_ms(2);
}
void CGRAM(int8 n){
lcd_send_byte(1,n);
}
void CGRAM_x(int p){
lcd_send_byte(0,0x40+p*8);
}
Hiç yorum yok:
Yorum Gönder
Her yorum bilgidir. Araştırmaya devam...