#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();
	}
}
