#include <stdio.h>
#include <ADuCM360.H>
#include <string.h>

void SER_Init (void);
void Send_Uart (char x);
void Send (char Buff[]);
void delay (long int length);

int main (void) {
	SER_Init();																			// iniciace uart
	
	while(1) 
		{
			int a=123456789;                      			// hodnota kterou posilám  
			char buffer[10] ; 
			sprintf(buffer, "%d", a);
			Send(buffer);																// posilání
			delay(3500000);                 						// delay
		}
}
void SER_Init (void) {
	pADI_CLKCTL->CLKCON0 = 0x0;											// UCLK, HFOSC,clock divide bit 1
	pADI_CLKCTL->CLKSYSDIV = 0x0;										// CD0 clock - 16Mhz 
	
  pADI_UART->COMCON= 0x0;  												// uart enable
	pADI_GP0->GPCON |= 0x3C; 												// P0.1/P0.2 pro UART
	pADI_UART->COMLCR= 0x3;  												// no parity, 1 stop bit, 8 data bits
	pADI_UART->COMDIV= 0x2;  												// comdiv=2
	pADI_UART->COMFBR= 0x915C; 											// baud rate 115200 divm=2 divn=348  0b1001000101011100
}
void Send_Uart (char x){
		while (!(pADI_UART->COMLSR == 0))							
    pADI_UART->COMTX=x;														// posilani 1 symbolu
}
void Send (char Buff[]) {
	int cnt=0; 
	int cnt1=0; 
	Send_Uart(0x02);                          			// zacatek zpravy
	delay(700);                         					 

	cnt1=strlen(Buff);															// cnt1=delka bufferu
			while (cnt<cnt1) 
				{															
				if (Buff[cnt]!=0) 
					{
						Send_Uart(Buff[cnt]);
						delay(500); 
					}
				cnt++;
			  }

	delay(700);                         						
	Send_Uart(0x0d);			                    			// konec zpravy
}
void delay (long int length)
{
   while (length >0)
      length--;
}
