Created
January 23, 2015 22:32
-
-
Save Microcontrolandos/ec02c67634cbfc979f6b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
LCD595 - LCD com 74HC595( Shift Register ) | |
Autor: Tiago | |
Compilador: MikroC PRO PIC | |
Criado em: 18/06/2014 por Tiago | |
Modificado em: 23/01/2015 por Tiago | |
- Adicionado as funções: LCD_Chr_CP e LCD_Out_CP | |
- Alterado as funções LCD_Chr e LCD_Out | |
- Alterado o nome da função LCD595_Write4Bit para LCD595_Send | |
/* | |
/* Pinos */ | |
extern sfr sbit LCD595_Data; | |
extern sfr sbit LCD595_Clock; | |
extern sfr sbit LCD595_Latch; | |
extern sfr sbit LCD595_Data_Direction; | |
extern sfr sbit LCD595_Clock_Direction; | |
extern sfr sbit LCD595_Latch_Direction; | |
/* Rotinas */ | |
static void LCD595_Send( char nibble ); | |
void LCD595_Cmd( char cmd ); | |
void LCD595_Set_Cursor( char row, char col ); | |
void LCD595_Chr_CP( char wData ); | |
void LCD595_Chr( char row, char col, char character ); | |
void LCD595_Out_CP( char *text ); | |
void LCD595_Out( char row, char col, char *text ); | |
void LCD595_Init(); | |
#define LCD595_Data( wData ) LCD595_Chr_CP( wData ) | |
/* Envia 4 bits */ | |
static void LCD595_Send( char nibble ) | |
{ | |
char i, k, aux = nibble; | |
LCD595_Clock = 0; | |
/* Enviar duas vezes para pulsar o pino E */ | |
for( k = 0; k < 2; k++ ) | |
{ | |
/* Pino E */ | |
LCD595_Data = !k.B0; | |
/* Pulso de clock desloca e carrega o bit no 74HC595 */ | |
LCD595_Clock = 1; | |
LCD595_Clock = 0; | |
/* Pino RS */ | |
LCD595_Data = nibble.B4; | |
/* Pulso de clock desloca e carrega o bit no 74HC595 */ | |
LCD595_Clock = 1; | |
LCD595_Clock = 0; | |
/* Pinos D4 - D7 */ | |
for( i = 0; i < 4; i++ ) | |
{ | |
LCD595_Data = nibble.B3; | |
/* Pulso de clock desloca e carrega o bit no 74HC595 */ | |
LCD595_Clock = 1; | |
LCD595_Clock = 0; | |
nibble <<= 1; | |
} | |
/* Atualiza as saídas do 74HC595 */ | |
LCD595_Latch = 1; | |
LCD595_Latch = 0; | |
LCD595_Data = 0; | |
nibble = aux; | |
Delay_us( 1 ); | |
} | |
Delay_us( 100 ); | |
} | |
/* Envia um comando */ | |
void LCD595_Cmd( char cmd ) | |
{ | |
LCD595_Send( cmd >> 4 ); | |
LCD595_Send( cmd & 0x0F ); | |
Delay_ms( 5 ); | |
} | |
/* Define a posição do cursor */ | |
void LCD595_Set_Cursor( char row, char col ) | |
{ | |
switch( row ) | |
{ | |
case 1: row = 192; break; | |
case 2: row = 148; break; | |
case 3: row = 212; break; | |
default: row = 128; | |
} | |
LCD595_Cmd( row + col ); | |
} | |
/* Envia um dado ou escreve um caracter na posição atual do cursor */ | |
void LCD595_Chr_CP( char character ) | |
{ | |
LCD595_Send( ( character >> 4 ) | 0x10 ); | |
LCD595_Send( ( character & 0x0F ) | 0x10 ); | |
} | |
/* Envia um dado ou escreve um caracter na posição especificada */ | |
void LCD595_Chr( char row, char col, char character ) | |
{ | |
LCD595_Set_Cursor( row, col ); | |
LCD595_Chr_CP( character ); | |
} | |
/* Escreve um texto na posição atual do cursor */ | |
void LCD595_Out_CP( char *text ) | |
{ | |
while( *text ) | |
LCD595_Chr_CP( *text++ ); | |
} | |
/* Escreve um texto na posição especificada */ | |
void LCD595_Out( char row, char col, char *text ) | |
{ | |
LCD595_Set_Cursor( row, col ); | |
LCD595_Out_CP( text ); | |
} | |
/* Inicializa o display LCD */ | |
void LCD595_Init() | |
{ | |
/* Define a direção dos pinos */ | |
LCD595_Data_Direction = 0; | |
LCD595_Clock_Direction = 0; | |
LCD595_Latch_Direction = 0; | |
Delay_ms( 50 ); | |
LCD595_Send( 3 ); | |
Delay_us( 4500 ); | |
LCD595_Send( 3 ); | |
Delay_us( 4500 ); | |
LCD595_Send( 3 ); | |
Delay_us( 150 ); | |
LCD595_Send( 2 ); | |
LCD595_Cmd( 0x28 ); //modo 4bits, 5x8, 2 linhas | |
LCD595_Cmd( 12 ); //Display ON | |
LCD595_Cmd( 6 ); //left, shift decrement | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment