#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;
}
这是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]);
}
我想在屏幕上显示x
的值,我的Lcd_pring_String
仅采用字符串类型。有什么方法可以将x
转换为字符串,以便我可以在LCD上显示?
我正在使用PIC16f877A,LCD(lm016)和两个开关来获取+ 1,-1的信号。