View previous topic :: View next topic |
Author |
Message |
sshahryiar
Joined: 05 May 2010 Posts: 94 Location: Dhaka, Bangladesh
|
3 Wire LCD with 4094 Shift Register |
Posted: Thu Aug 27, 2015 4:54 am |
|
|
LCD.h
Code: |
#define SDO pin_A0
#define SCK pin_A1
#define STB pin_A2
#define clear_display 0x01
#define goto_home 0x02
#define cursor_direction_inc (0x04 | 0x02)
#define cursor_direction_dec (0x04 | 0x00)
#define display_shift (0x04 | 0x01)
#define display_no_shift (0x04 | 0x00)
#define display_on (0x08 | 0x04)
#define display_off (0x08 | 0x02)
#define cursor_on (0x08 | 0x02)
#define cursor_off (0x08 | 0x00)
#define blink_on (0x08 | 0x01)
#define blink_off (0x08 | 0x00)
#define _8_pin_interface (0x20 | 0x10)
#define _4_pin_interface (0x20 | 0x00)
#define _2_row_display (0x20 | 0x08)
#define _1_row_display (0x20 | 0x00)
#define _5x10_dots (0x20 | 0x40)
#define _5x7_dots (0x20 | 0x00)
#define dly 0x01
unsigned char data_value = 0x00;
void SIPO();
void LCD_init();
void LCD_command(unsigned char value);
void LCD_send_data(unsigned char value);
void LCD_4bit_send(unsigned char lcd_data);
void LCD_putstr(char *lcd_string);
void LCD_putchar(char char_data);
void LCD_clear_home();
void LCD_goto(unsigned char x_pos, unsigned char y_pos);
|
LCD.c
Code: |
#include "lcd.h"
void SIPO()
{
unsigned char clk = 0x08;
unsigned char temp = 0x00;
temp = data_value;
output_low(STB);
while(clk > 0)
{
output_bit(SDO, (temp & 0x80));
output_high(SCK);
temp <<= 1;
clk--;
output_low(SCK);
}
output_high(STB);
}
void LCD_init()
{
unsigned char t = 0x0A;
data_value = 0x08;
SIPO();
while(t > 0x00)
{
delay_ms(dly);
t--;
};
data_value = 0x30;
SIPO();
data_value |= 0x08;
SIPO();
delay_ms(dly);
data_value &= 0xF7;
SIPO();
delay_ms(dly);
data_value = 0x30;
SIPO();
data_value |= 0x08;
SIPO();
delay_ms(dly);
data_value &= 0xF7;
SIPO();
delay_ms(dly);
data_value = 0x30;
SIPO();
data_value |= 0x08;
SIPO();
delay_ms(dly);
data_value &= 0xF7;
SIPO();
delay_ms(dly);
data_value = 0x20;
SIPO();
data_value |= 0x08;
SIPO();
delay_ms(dly);
data_value &= 0xF7;
SIPO();
delay_ms(dly);
LCD_command(_4_pin_interface | _2_row_display | _5x7_dots);
LCD_command(display_on | cursor_off | blink_off);
LCD_command(clear_display);
LCD_command(cursor_direction_inc | display_no_shift);
}
void LCD_command(unsigned char value)
{
data_value &= 0xFB;
SIPO();
LCD_4bit_send(value);
}
void LCD_send_data(unsigned char value)
{
data_value |= 0x04;
SIPO();
LCD_4bit_send(value);
}
void LCD_4bit_send(unsigned char lcd_data)
{
unsigned char temp = 0x00;
temp = (lcd_data & 0xF0);
data_value &= 0x0F;
data_value |= temp;
SIPO();
data_value |= 0x08;
SIPO();
delay_ms(dly);
data_value &= 0xF7;
SIPO();
delay_ms(dly);
temp = (lcd_data & 0x0F);
temp <<= 0x04;
data_value &= 0x0F;
data_value |= temp;
SIPO();
data_value |= 0x08;
SIPO();
delay_ms(dly);
data_value &= 0xF7;
SIPO();
delay_ms(dly);
}
void LCD_putstr(char *lcd_string)
{
while (*lcd_string != '\0')
{
LCD_send_data(*lcd_string);
lcd_string++;
};
}
void LCD_putchar(char char_data)
{
LCD_send_data(char_data);
}
void LCD_clear_home()
{
LCD_command(clear_display);
LCD_command(goto_home);
}
void LCD_goto(unsigned char x_pos,unsigned char y_pos)
{
if(y_pos == 0)
{
LCD_command(0x80 | x_pos);
}
else
{
LCD_command(0x80 | 0x40 | x_pos);
}
}
|
Example:
Code: |
#include <12F675.h>
#device *= 16
#fuses NOWDT, PROTECT, CPD, NOMCLR, INTRC_IO, BROWNOUT, PUT
#use delay (internal = 4MHz)
#include "lcd.c"
void setup();
void main()
{
char txt1[] = {"MicroArena"};
char txt2[] = {"SShahryiar"};
setup();
LCD_goto(3, 0);
LCD_putstr(txt1);
LCD_goto(3, 1);
LCD_putstr(txt2);
while(TRUE)
{
};
}
void setup()
{
disable_interrupts(GLOBAL);
setup_comparator(NC_NC_NC_NC);
setup_ADC(ADC_off);
setup_ADC_ports(no_analogs);
setup_timer_0(T0_internal);
setup_timer_1(T1_disabled);
set_timer0(0);
set_timer1(0);
LCD_init();
LCD_clear_home();
delay_ms(200);
}
|
_________________ https://www.facebook.com/MicroArena
SShahryiar |
|
|
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
|
Posted: Fri Aug 28, 2015 6:24 pm |
|
|
has this ever been BUILT with hardware and checked?
or is this 101% Proteus/Isis ? |
|
|
sshahryiar
Joined: 05 May 2010 Posts: 94 Location: Dhaka, Bangladesh
|
|
|
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
|
Posted: Fri Aug 28, 2015 7:33 pm |
|
|
thats good to see. Nicely done. |
|
|
Nascimento
Joined: 30 Dec 2015 Posts: 3
|
|
Posted: Thu Dec 31, 2015 8:04 am |
|
|
hi friend you could send the pcb 4094?
ps: google translator |
|
|
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
|
Posted: Thu Dec 31, 2015 4:05 pm |
|
|
i don't understand why you don't use the 74HC595 for which CCS provides a driver in the examples section.
name 74595.c in the DRIVERS folder of your CCS install
here is a link to the datasheet for the 4094 which i do NOT reccomend.
http://www.mouser.com/ds/2/405/cd4094b-439708.pdf |
|
|
|