Objectives:
- Start to programming for LCD string
- To show output in LCD
Contents:
- For make sure this programming suitable in LCD 4x16
//Project: GSM Solar Monitoring
//Programmer:Khairul Hasnadi Mohmad
//PIC: PIC16F887
//Crystal Frequency: 20MHz
//Compiler: HI-TECH ANSI C V9.83
//Last Modified: 14 August 2012
//Website: http://hasnady.blogspot.com
#define PUSH_BUTTON
#define ADC
#define UART
#define I2C
#define HD44780
#define GSM_MODEM
#define PULSE 9000
#define SEL RC0
#include <htc.h>
#include "LibraryHardware.h"
#include "LibraryPeripheral.h"
#include "LibraryUniversalDisplay.h"
#include "LibraryAtCommand.h"
#include "LibraryDS1307.h"
void pic_init(void);
char read_button(void);
char sms(void);
unsigned int counter[3];
__EEPROM_DATA('0','1','3','6','2','8','9','8'); //memory data can save 256 Byte
__EEPROM_DATA('4','4',1,1,0,0,0,0);
__EEPROM_DATA(0,0,0,0,0,0,0,0);
__EEPROM_DATA(0,0,0,0,0,0,0,0);
__EEPROM_DATA(0,0,0,0,0,0,0,0);
__EEPROM_DATA(0,0,0,0,0,0,0,0);
__EEPROM_DATA(0,0,0,0,0,0,0,0);
__EEPROM_DATA(0,0,0,0,0,0,0,0);
__EEPROM_DATA(0,0,0,0,0,0,0,0);
__EEPROM_DATA(0,0,0,0,0,0,0,0);
__EEPROM_DATA(0,0,0,0,0,0,0,0);
__EEPROM_DATA(0,0,0,0,0,0,0,0);
__EEPROM_DATA(0,0,0,0,0,0,0,0);
__EEPROM_DATA(0,0,0,0,0,0,0,0);
static void interrupt isr(void)
{
if(RCIF==1){ // Receive message
counter[0]=0;
get_phone_message();}
if(TMR0IF==1){ // Time Receive message
TMR0IF=0;
reset_yz();
if(counter[0]<PULSE) counter[0]++;
else counter[0]=0;
}
}
main()
{
unsigned char button,temp,disp=0,mode=0;
unsigned char set=0,mo[12]={31,28,31,30,31,30,31,31,30,31,30,31};
unsigned char sec,min,hrs,date,month,year,time[2];
int i,j,voltage,current;
pic_init(); //initialize PIC
uart_init(9600); //initialize UART
i2c_init(10); //initialize I2C
lcd_init(); //initialize LCD
phone[0]='+';
phone[1]='6';
for(i=0;i<=9;i++) phone[i+2]=eeprom_read(i);
phone[12]=0xFF;
for(i=0;i<=1;i++) time[i]=eeprom_read(i+10);
lcd_goto(0,0); //select first line
lcd_string(" GSM MODEM "); // Show the " GSM MODEM" in first line
while(gsm_ready()==0) continue;
lcd_goto(0,1); //select second line
lcd_string(" READY "); // Show "READY" in second line
sms_delete(1);
delay(1000);
#if defined (PCD8544)
/* initialise the GLCD */ //we use the LCD 4x16
void glcd_init(void)
{
GLCD_RST=1; // graphical LCD
__delay_ms(15);
glcd_write(0x21); //function set
glcd_write(0xC0); //set Vlcd
glcd_write(0x13); //set Bias System
glcd_write(0x20); //function set
glcd_write(0x0C); //sets display configuration
}
/* write serial byte to the GLCD */
void glcd_write(unsigned char c)
{int i;
GLCD_CS=0;
for(i=0;i<=7;i++){
GLCD_SDA=(c>>(7-i))&1;
GLCD_SCLK=0;
GLCD_SCLK=1;}
GLCD_CS=1;
}
/* go to the specified x&y location */
void glcd_goto(char x, char y)
{
GLCD_DC=0;
glcd_write(0x80+x);
glcd_write(0x40+y);
GLCD_DC=1;
}
/* write a character to the LCD */
void glcd_char(char c)
{int i;
if((c<32)|(c>127)) c=' ';
for(i=0;i<5;i++) glcd_write(FontLookup[c-32][i]);
glcd_write(0x00);
}
/* write a string of chars to the GLCD */
void glcd_string(const char *s)
{
GLCD_DC=1;
while(*s)
glcd_char(*s++);
}
void glcd_number(unsigned int no, char base, char digit)
{char i,j,di[10];
for(i=0;i<=9;i++) di[i]=0;
i=0;
do{
di[i]=no%base;
no=no/base;
i=i+1;}
while(no!=0);
for(j=digit;j>0;j--){
if(di[j-1]<=9) glcd_char(di[j-1]+'0');
else glcd_char(di[j-1]-10+'A');}
}
#endif
Result&Analysis
- Programming successful for LCD screen 2X16 when the compiler in mp lab not detect another problem in the programming.
Conclusion
- As a conclusion, i know how to program of the LCD screen in PIC 16F887. For next step, i need to program for the push button for select the time.
No comments:
Post a Comment