Вы находитесь на странице: 1из 5

#include <hidef.

h>
#include "derivative.h"
void uart0_9600_init(void);
unsigned char uart0_rx(void);
void uart0_tx(unsigned char a);
void uart0_tx_string(char *s) ;
void uart0_tx_number(unsigned char a);
void Delay(unsigned char a);
void uart0_tx_newline(void);
void display_menu(void);
void uart0_tx_int(unsigned int a);

void main(void) {
unsigned int flag1,flag2 ;
char i,j,ind[3];
unsigned long cnt;
char ans;
unsigned char w[7], temp;
unsigned char b[7], org[7];
unsigned char cr[7] ,cv[7],b_s[7],senspos[7];
uart0_9600_init();
//Display Menu
uart0_tx(0x0C);
//w==010 009 010 009 009 010 011
//b==205 152 184 174 193 136 205
w[6]=10;
w[5]=9;
w[4]=10 ;
w[3]=9;
w[2]=9;
w[1]=10 ;
w[0]=11;
b[6] =205;
b[5] =152;
b[4] =184;
b[3] =174;
b[2] =193;
b[1] =136;
b[0] =205;
senspos[6] = 3072;
senspos[5] = 2560;
senspos[4] = 2048;
senspos[3] = 1536;
senspos[2] = 1024;
senspos[1] = 512;
senspos[0] = 0;
for(i=6;i>=0;i--) {
cr[i]= 255/(b[i] - w[i]);
}
for(;;){
//Read ATD values
ATD0CTL1=0x87; // no external trigger
ATD0CTL2_ADPU=1; // ATD Enable
ATD0CTL2_ETRIGE=0; // no external trigger
ATD0CTL3_S8C=1; // 8 adc channels sequence
ATD0CTL4_SRES8=1; // 8-bit Resolution
ATD0CTL5=0x10; // multisequence
org[6]= ATD0DR6H ;
org[5] = ATD0DR5H ;
org[4] = ATD0DR4H ;
org[3] =ATD0DR3H ;
org[2] = ATD0DR2H ;
org[1] = ATD0DR1H ;
org[0] = ATD0DR0H ;

for(i=6;i>=0;i--) {
if(org[i]<=w[i]){
b_s[i]= cv[i]=w[i];
} else if(org[i]>=b[i]){
b_s[i]=cv[i]=b[i];
} else
b_s[i]=cv[i]= (org[i]- w[i] )* cr[i] ;
}
for(i=6;i>=0;i--){
for(j=i-1;j>=0;j--){
if(cv[i]<cv[j]) {
temp=cv[i];
cv[i]=cv[j];
cv[j]=temp;
}
}
}

for(i=6;i>=0;i--) {
uart0_tx_string(" ");
uart0_tx_number(org[i]);
}
uart0_tx_newline();

for(i=6;i>=0;i--) {
uart0_tx_string(" ");
uart0_tx_number(b_s[i]);
}
uart0_tx_newline();
for(i=6;i>=0;i--) {
uart0_tx_string(" ");
uart0_tx_number(cv[i]);
}
uart0_tx_newline();
uart0_tx_newline();
for(i=6;i>=4;i--){
for(j=6;j>=0;j--){
if(cv[i]==b_s[j])
ind[i-4]=j;
}
}
for(i=2;i>=0;i--){
for(j=i-1;j>=0;j--){
if(ind[i]<ind[j]) {
temp=ind[i];
ind[i]=ind[j];
ind[j]=temp;
}
}
}

for(i=2;i>=0;i--) {
uart0_tx_string(" ");
uart0_tx_number(ind[i]);
}
uart0_tx_newline();
for(i=2;i>=0;i--) {
uart0_tx_string(" ");
uart0_tx_number(b_s[ind[i]]);
}
uart0_tx_newline();

Delay(10);
}
}

void display_menu(void) {

uart0_tx_newline();
uart0_tx_string("============================================================");
uart0_tx_newline();
uart0_tx_string(" Board test: Enter following number");
uart0_tx_newline();
uart0_tx_string("1:To Test LEDs");
uart0_tx_newline();
uart0_tx_string("2:To Test Switch");
uart0_tx_newline();
uart0_tx_string("3:To Test DC Motor");
uart0_tx_newline();
uart0_tx_string("4:To Test Servo Motor");
uart0_tx_newline();
uart0_tx_string("5:To Check Analog to Digital values");
uart0_tx_newline();
uart0_tx_string("6:To check Pulse counter value");
uart0_tx_newline();
uart0_tx_string("============================================================");
uart0_tx_newline();
}
void Delay(unsigned char a) {
unsigned int i,j;
for(j=1;j<=a;j++) //Delay
for(i=0;i<=60000;i++);
}
//UART functions.....
void uart0_9600_init(void) {
SCI0BDL=13;
SCI0CR1=0;
SCI0CR2=12;
}

void uart0_tx_int(unsigned int a) {


unsigned int temp;
temp=a/10000;
uart0_tx(temp + 0x30);
a=a-temp*10000;
temp=a/1000;
uart0_tx(temp + 0x30);
a=a-temp*1000;
temp=a/100;
uart0_tx(temp + 0x30);
a=a-temp*100;
temp=a/10;
uart0_tx(temp + 0x30);
a=a-temp*10;
uart0_tx(a + 0x30);
}
void uart0_tx_number(unsigned char a) {
char temp;
temp=a/100;
uart0_tx(temp + 0x30);
a=a-temp*100;
temp=a/10;
uart0_tx(temp + 0x30);
a=a-temp*10;
uart0_tx(a + 0x30);
}
void uart0_tx_string(char *s) {
while (*s)
{
uart0_tx(*s);
s++;
}
}
void uart0_tx_newline(void) {
uart0_tx(0x0A);
uart0_tx(0x0D);
}
unsigned char uart0_rx(void) {
while(SCI0SR1_RDRF==0);
return SCI0DRL;
}

void uart0_tx(unsigned char a) {


SCI0DRL=a;
while(SCI0SR1_TC==0);
}

Вам также может понравиться