void WrCmd2Lcd(char cmd);
void WrDat2Lcd(char data);
void InitLcd();
void Speech(char words,int position);
void main()
{
char hello[]="HELLO WORLD!\n";
#define lcd_rs PIN_B0
#define lcd_rw PIN_B1
#define lcd_e PIN_B2
#define lcd_cmd_wri 0x00
#define lcd_data_wri 0x01
#define lcd_set_function 0x38
#define lcd_set_visible 0x0F
#define lcd_set_shift 0x16
#define lcd_set_mode 0x06
#define lcd_set_home_address 0x00
#define lcd_clear 0x01
#define lcd_init 0x30
set_tris_a(0x0f);
set_tris_b(0x00);
set_tris_c(0x00);
set_tris_d(0x00); // to LCD D0-D7
output_high(PIN_C0); //affect relay and it works well
InitLcd();
Speech(hello,0x00); //
}
void WrCmd2Lcd(char cmd)
{
output_d(cmd);
output_b(lcd_cmd_wri);
output_high(lcd_e);
#asm
nop
#endasm
output_low(lcd_e);
}
void WrDat2Lcd(char data)
{
output_d(data);
output_b(lcd_data_wri);
output_high(lcd_e);
#asm
nop
#endasm
output_low(lcd_e);
delay_ms(1);
}
void InitLcd()
{
delay_ms(16);
WrCmd2Lcd(lcd_init);
delay_ms(5);
WrCmd2Lcd(lcd_init);
delay_cycles(200);
WrCmd2Lcd(lcd_init);
delay_cycles(100);
WrCmd2Lcd(lcd_set_function);
delay_cycles(100);
WrCmd2Lcd(lcd_set_visible);
delay_cycles(100);
}
void Speech(char words,int position)
{
char *textptr;
textptr = words;
WrCmd2Lcd(position);
delay_ms(64);
do
{
WrDat2Lcd(*textptr);
*textptr++;
}
while(*textptr != '\n');
}
Could you tell me why I should need to set up CGRAM when initiate LCD ?VSMVDD said:then in main you just need to call the init branch in the class
void LCD_INITIALMODE ( int CGCHARSET ); << this needs set to 1 or 2
to setup the cgram charset in use
[size=9]
// MNEMONICS FOR BUTTONS
#define row1 PIN_A0
#define row2 PIN_A1
#define row3 PIN_A2
#define row4 PIN_A3
#define col1 PIN_D3
#define col2 PIN_D2
#define col3 PIN_D1
#define col4 PIN_D0
// MNEMONICS FOR LCD
#define lcd_rs PIN_B0
#define lcd_rw PIN_B1
#define lcd_e PIN_B2
#define lcd_cmd_wri 0x00
#define lcd_data_wri 0x01
#define lcd_busy_rd 0x02
#define lcd_set_function 0x38 //8 bit interface, 2 line mode, 5x7 dot format
#define lcd_set_visible 0x0F //Display on, cursor underline on, cursor blink on
#define lcd_set_shift 0x16 //Cursor move, Right shift
#define lcd_set_mode 0x06 //Increment, display shift off
#define lcd_set_cgaddr 0x40
#define lcd_set_ddaddr 0x80
#define lcd_clr 0x01
#define lcd_init 0x30
#include "D:\Pic16F877\MyProject\Doit\Doit.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void LcdEnable();
void WrCmd2Lcd(char cmd);
void WrDat2Lcd(char data);
void InitLcd();
void Speech(char words,int position);
void LcdWait();
void LcdPutPar(int par);
void main()
{
//INTRO OR GUIDED WORDS
char hello[]="HELLO WORLD!\n";
//PIC SET-UP PARAMETERS
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_psp(PSP_DISABLED);
setup_spi(FALSE);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
// TODO: USER CODE!!
set_tris_a(0x0f);
set_tris_b(0x00);
set_tris_c(0x00);
output_high(PIN_C0);
InitLcd();
WrDat2Lcd("A");
// for(;;)
Speech(hello,lcd_set_ddaddr+0x40);
}
void LcdEnable()
{
output_high(lcd_e);
delay_us(10);
output_low(lcd_e);
}
void WrCmd2Lcd(char cmd)
{
set_tris_d(0x00);
LcdPutPar(cmd);
output_b(lcd_cmd_wri);
LcdEnable();
// LcdWait();
}
void WrDat2Lcd(char data)
{
set_tris_d(0x00);
LcdPutPar(data);
output_b(lcd_data_wri);
LcdEnable();
LcdWait();
}
void InitLcd()
{
output_low(lcd_e);
delay_ms(125);
WrCmd2Lcd(lcd_init);
delay_ms(20);
LcdEnable();
delay_us(200);
LcdEnable();
delay_us(100);
WrCmd2Lcd(lcd_set_function);
delay_ms(10);
WrCmd2Lcd(lcd_set_visible);
delay_ms(10);
// WrCmd2Lcd(lcd_clr);
// delay_us(100);
WrCmd2Lcd(lcd_set_mode);
delay_ms(10);
// WrCmd2Lcd(lcd_set_ddaddr);
// delay_us(100);
}
void Speech(char words,int position)
{
char *textptr;
textptr = words;
WrCmd2Lcd(position);
LcdWait();
delay_ms(64);
do
{
WrDat2Lcd(*textptr);
*textptr++;
}
while(*textptr != '\n');
}
void LcdWait()
{
int status;
set_tris_d(0xFF);
output_b(lcd_busy_rd);
do
{
output_high(lcd_e);
status=input_d();
output_low(lcd_e);
}
while(status & 0x80); // test busy flag.
}
void LcdPutPar(int par)
{
output_bit(PIN_D0,par & 0X01 );
output_bit(PIN_D1,par & 0X02 );
output_bit(PIN_D2,par & 0X04 );
output_bit(PIN_D3,par & 0X08 );
output_bit(PIN_D4,par & 0X10 );
output_bit(PIN_D5,par & 0X20 );
output_bit(PIN_D6,par & 0X40 );
output_bit(PIN_D7,par & 0X80 );
}
[/size]
void WrCmd2Lcd(char cmd)
{
set_tris_d(0x00);
output_low(lcd_rw);
output_high(lcd_rs);
output_d(cmd);
output_low(lcd_rs);
LcdEnable();
}
void WrDat2Lcd(char data)
{
set_tris_d(0x00);
output_high(lcd_rs);
output_low(lcd_rw);
output_low(lcd_rs);
output_d(data);
LcdEnable();
output_high(lcd_rs);
output_high(lcd_e);
}
...
void main()
{
//INTRO OR GUIDED WORDS
char hello[]="HELLO WORLD! ";
char keyPressed;
//PIC SET-UP PARAMETERS
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_psp(PSP_DISABLED);
setup_spi(FALSE);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
// TODO: USER CODE!!
set_tris_b(0x00);
set_tris_c(0x00);
InitLcd();
WrDat2Lcd("A");
play:
keyPressed=OnRelease();
if(keyPressed!=" ")
{
WrDat2Lcd(keyPressed);
}
goto play;
// WrDat2Lcd("B");
// Speech(hello,lcd_set_ddaddr+0x40);
}
....
char OnRelease()
{
int i,j,k;
int row[4]={PIN_A0,PIN_A1,PIN_A2,PIN_A3};
int col[4]={PIN_D3,PIN_D2,PIN_D1,PIN_D0};
char array[16]={'1','4','7','<','2','5','8','0','3','6','9','>','C','&','E','M'};
set_tris_a(0xff);
set_tris_d(0x00);
loop:
k=0;
for(i=0;i<4;i++)
{
output_d(0xff);
output_low(col[i]);
for(j=0;j<4;j++)
{
if(input(row[j])==0)
{
do
{
}
while(input(row[j])==0);
goto end;
}
k++;
}
}
goto loop;
end:
return array[k];
}
...
char OnRelease()
{
int i,j,k;
int row[4]={PIN_A0,PIN_A1,PIN_A2,PIN_A3};
int col[4]={PIN_D3,PIN_D2,PIN_D1,PIN_D0};
char array[16]={'1','4','7','<','2','5','8','0','3','6','9','>','C','&','E','M'};
set_tris_a(0xff);
set_tris_d(0x00);
k=0;
for(i=0;i<4;i++)
{
output_d(0xff);
output_low(col[i]);
for(j=0;j<4;j++)
{
if(input(row[j])==0)
{
do
{
}
while(input(row[j])==0);
return array[k]; //// how to jump out of this function with the value I got ???
}
k++;
}
}
return null; //?????
}
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?