This repository has been archived on 2024-01-06. You can view files and clone it, but cannot push or open issues or pull requests.
justhomework/MCU/MCU_6 _UART/main.c

68 lines
924 B
C
Raw Normal View History

2022-04-28 02:00:04 +00:00
#include "delay.h"
#include "main.h"
#include "display.h"
#include <stdio.h>
unsigned char text[20];
unsigned int digital;
unsigned int digital_old;
void sendByte(unsigned char byte)
{
SBUF=byte;
while(!TI);
TI=0;
}
void sendString(unsigned char *s)
{
while(*s!='\0')
{
SBUF=*s;
s++;
while(!TI);
TI=0;
}
}
unsigned char ADC_read()
{
XBYTE[0X8000]=0X00;
delay(2);
return XBYTE[0X8000];
}
int main()
{
//P1 AD
unsigned char temp;
set_display(0);
setConfig();
sendString("Hello\n");
while(1)
{
temp=ADC_read();
digital=ADC_read();
if(digital!=digital_old)
{
digital_old=digital;
set_display(digital);
sprintf(text,"Digital Voltage %u \n",digital);
sendString(text);
}
if(RI)
{
RI = 0;
temp = SBUF;
if(0x40<temp&&temp<0x5b)
SBUF = temp+0x20;
else if(0x60<temp&&temp<0x7b)
SBUF=temp-0x20;
}
fresh_display();
}
}