#include <xc.h>
#include "LCD.h"
#include <stdio.h>
#include <stdlib.h>
int main()
{
unsigned int a; int x = 0; char s[10000];
TRISD = 0x00; TRISB = 0x03;
Lcd_Start();
while(1)
{
Lcd_Clear();Lcd_Set_Cursor(1,1);
int x = 0;
if (PORTBbits.RB0==1)
{
Lcd_Clear();
x += 1;
Lcd_Print_String("Current Number");
Lcd_Set_Cursor(2,1);
Lcd_Print_String(x)
}
else if(PORTBbits.RB1==1)
{
Lcd_Clear();
x += -1;
Lcd_Print_String("Current Number");
Lcd_Set_Cursor(2,1);
Lcd_Print_String(x);
}
}
return 0;
}
This is Lcd_Print_String
:
void Lcd_Print_Char(char data) //Send 8-bits through 4-bit mode
{
char Lower_Nibble,Upper_Nibble;
Lower_Nibble = data&0x0F;
Upper_Nibble = data&0xF0;
RS = 1; // => RS = 1
Lcd_SetBit(Upper_Nibble>>4); //Send upper half by shifting by 4
EN = 1;
for (int i=2130483; i<=0; i--) NOP();
EN = 0;
Lcd_SetBit(Lower_Nibble); //Send Lower half
EN = 1;
for (int i=2130483; i<=0; i--) NOP();
EN = 0;
}
void Lcd_Print_String(char *a)
{
int i;
for (i=0;a[i]!='\0';i++)
Lcd_Print_Char(a[i]);
}
I want to display the value of x
on the screen, my Lcd_pring_String
only takes string type. Is there a way convert x
to a string so I can display on LCD?
I am using PIC16f877A, LCD(lm016) and two switches to take signal for +1, -1.