lcd 4094 entegre kütüphanesini ekleyerek çalıştırıyoruz.12f683 denetleyici kullanıldı.kod ve devresi aşağıda verildi.
YouTube kanalında videosunu izleyebilirisiniz
main.c alttaki kodları .c olarak kaydedelim.
#include <12f683.h>
//4094 LCD Serial
#device ADC=10
#FUSES NOWDT
#FUSES HS
#FUSES NOPUT
#FUSES NOPROTECT
#fuses nomclr
#fuses INTRC_IO
#use delay(clock=4000000)
int i;
int16 dat=0;
unsigned long int okunan;
float voltaj;
//4094 PINs
#define data PIN_a0
#define clock PIN_a1
#define Strobe PIN_a2
#include "lcd4094.c"
void main(){
set_tris_a(0x00);
output_a(0x0f);
setup_adc(adc_clock_div_32);
setup_adc_ports(sAN3);
lcd_init();
//lcd_goto_xy(1,1);
// printf(LCD_PUTC,"isi: %.2f",voltaj);
lcd_goto_xy(1,2);
printf(LCD_PUTC,"4094 Serial LCD");
/*
lcd_goto_xy(21,1);
printf(lcd_putc,"3 SATIR ");//3 satir
lcd_goto_xy(21,2);
printf(lcd_putc,"4 SATIR ");//4 satir
*/
delay_ms(500);
while(true){
set_adc_channel(3);
delay_us(20);
okunan = read_adc();
voltaj = (okunan * 0.00488) * 100;
lcd_goto_xy(1,1);
printf(LCD_PUTC,"isi: %.2f",voltaj);
dat++;
lcd_goto_xy(30,1);
printf(LCD_PUTC,"%05ld ",dat);
}
}
-------------------------------------
LCD4094.c alttaki kodları .c olarak kaydedelim.
//4094(Shift Register) 3wire Serial To Parallel
byte d0,d1,d2,d3,d4,d5,d6,d7;
/*
#IFNDEF data
#define data PIN_A0
#define clock PIN_A1
#define strobe PIN_A2
#ENDIF
*/
//4094 Shift Register
void set_shift(int8 value)
{
int8 location=0,n=0;
location=128;
for(n=1;n<=8;n++){
if ((value & location)>0) output_bit(data,1); else output_bit(data, 0);
output_bit(clock,1);
location=location / 2;
output_bit(clock,0);
}
output_bit(strobe,1);
output_bit(strobe,0);
}
void f_output(byte value)
{
set_shift(value);
}
void fatport()
{
int value;
value=0;
if (d0==1) value=value+1;
if (d1==1) value=value+2;
if (d2==1) value=value+4;
if (d3==1) value=value+8;
if (d4==1) value=value+16;
if (d5==1) value=value+32;
if (d6==1) value=value+64;
if (d7==1) value=value+128;
f_output(value);
}
void dg0(int value)
{
d0=value;
fatport();
}
void dg1(int value)
{
d1=value;
fatport();
}
void dg2(int value)
{
d2=value;
fatport();
}
void dg3(int value)
{
d3=value;
fatport();
}
void dg4(int value)
{
d4=value;
fatport();
}
void dg5(int value)
{
d5=value;
fatport();
}
void dg6(int value)
{
d6=value;
fatport();
}
void dg7(int value)
{
d7=value;
fatport();
}
void f_output_bit(byte pin,value)
{
switch(pin)
{
case 1:dg0(value);
break;
case 2:dg1(value);
break;
case 3:dg2(value);
break;
case 4:dg3(value);
break;
case 5:dg4(value);
break;
case 6:dg5(value);
break;
case 7:dg6(value);
break;
case 8:dg7(value);
break;
}
}
void f_output_high(byte pin)
{
switch(pin)
{
case 1:dg0(1);
break;
case 2:dg1(1);
break;
case 3:dg2(1);
break;
case 4:dg3(1);
break;
case 5:dg4(1);
break;
case 6:dg5(1);
break;
case 7:dg6(1);
break;
case 8:dg7(1);
break;
}
}
void f_output_low(byte pin)
{
switch(pin)
{
case 1:dg0(0);
break;
case 2:dg1(0);
break;
case 3:dg2(0);
break;
case 4:dg3(0);
break;
case 5:dg4(0);
break;
case 6:dg5(0);
break;
case 7:dg6(0);
break;
case 8:dg7(0);
break;
}
}
///////////////////////////////////////////////////////////////////// flex_lcd.c
// pins to fit your own board.
#define LCD_DB4 5
#define LCD_DB5 6
#define LCD_DB6 7
#define LCD_DB7 8
#define LCD_E 4
#define LCD_RS 3
//#define LCD_RW -->> GND
//========================================
#define lcd_type 2 // 0=5x7, 1=5x10, 2=2 lines
#define lcd_line_two 0x40 // LCD RAM address for the 2nd line
int8 const LCD_INIT_STRING[4] =
{
0x20 | (lcd_type << 2), // Func set: 4-bit, 2 lines, 5x8 dots
0xc, // Display on
1, // Clear display
6 // Increment cursor
};
//-------------------------------------
void lcd_send_nibble(int8 nibble)
{
// Note: !! converts an integer expression
// to a boolean (1 or 0).
f_output_bit(LCD_DB4, !!(nibble & 1));
f_output_bit(LCD_DB5, !!(nibble & 2));
f_output_bit(LCD_DB6, !!(nibble & 4));
f_output_bit(LCD_DB7, !!(nibble & 8));
delay_cycles(1);
f_output_high(LCD_E);
delay_us(2);
f_output_low(LCD_E);
}
//----------------------------------------
// Send a byte to the LCD.
void lcd_send_byte(int8 address, int8 n)
{
f_output_low(LCD_RS);
delay_us(60);
if(address)
f_output_high(LCD_RS);
else
f_output_low(LCD_RS);
delay_cycles(1);
f_output_low(LCD_E);
lcd_send_nibble(n >> 4);
lcd_send_nibble(n & 0xf);
}
//----------------------------
void lcd_init(void)
{
int8 i;
f_output_low(LCD_RS);
f_output_low(LCD_E);
delay_ms(15);
for(i=0 ;i < 3; i++)
{
lcd_send_nibble(0x03);
delay_ms(5);
}
lcd_send_nibble(0x02);
for(i=0; i < sizeof(LCD_INIT_STRING); i++)
{
lcd_send_byte(0, LCD_INIT_STRING[i]);
}
}
//----------------------------
void lcd_goto_xy(int8 x, int8 y)
{
int8 address;
if(y != 1)
address = lcd_line_two;
else
address=0;
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_goto_xy(1,2);
break;
case '\b':
lcd_send_byte(0,0x10);
break;
default:
lcd_send_byte(1,c);
break;
}
}
Hiç yorum yok:
Yorum Gönder
Her yorum bilgidir. Araştırmaya devam...