Sie sind auf Seite 1von 3

/*

* main implementation: use this 'C' sample to create your own application
*
*/
#include "derivative.h" /* include peripheral declarations */
#include "adc.h"
#include "setup.h"

uint16_t Sensor_TM;
uint16_t data;

int Display_1A = 0x00000100;


int Display_1B = 0x00000200;
int Display_1C = 0x00000400;
int Display_1D = 0x00000800;

int Display_2A = 0x00000004;


int Display_2B = 0x00000008;
int Display_2C = 0x00000010;
int Display_2D = 0x00000020;

float centi()
{
data = adc_read( ADC_5 );
float c = (data * 500.0)/101033;
return (c);
}

int main(void)
{
setup();
adc_init( _16BIT );
int Display1;
int Display2;

for(;;)
{
Sensor_TM = (int)centi();
Display1 = Sensor_TM % 10;
Display2 = Sensor_TM / 10;

Escritura7448_01(Display1);
Escritura7448_02(Display2);
delay();

}
return 0;
}

void delay(void)
{
int counter;

for(counter=0; counter<400000; counter++)


{

}
}

void Escritura7448_01(short numero)


{
short BIT[4];

BIT[0] = ((numero & 1) == 1);


BIT[1] = ((numero & 2) == 2);
BIT[2] = ((numero & 4) == 4);
BIT[3] = ((numero & 8) == 8);

if(BIT[0] == 1)
GPIOB_PSOR = Display_1A;
else
GPIOB_PCOR = Display_1A;
if(BIT[1] == 1)
GPIOB_PSOR = Display_1B;
else
GPIOB_PCOR = Display_1B;
if(BIT[2] == 1)
GPIOB_PSOR = Display_1C;
else
GPIOB_PCOR = Display_1C;
if(BIT[3] == 1)
GPIOB_PSOR = Display_1D;
else
GPIOB_PCOR = Display_1D;
if((BIT[0] == 0) && (BIT[1] == 0) && (BIT[2] == 0) && (BIT[3] == 0))
GPIOB_PDOR = 0x00000000;
}

void Escritura7448_02(short numero)


{
short BIT[4];

BIT[0] = ((numero & 1) == 1);


BIT[1] = ((numero & 2) == 2);
BIT[2] = ((numero & 4) == 4);
BIT[3] = ((numero & 8) == 8);

if(BIT[0] == 1)
GPIOE_PSOR = Display_2A;
else
GPIOE_PCOR = Display_2A;
if(BIT[1] == 1)
GPIOE_PSOR = Display_2B;
else
GPIOE_PCOR = Display_2B;
if(BIT[2] == 1)
GPIOE_PSOR = Display_2C;
else
GPIOE_PCOR = Display_2C;
if(BIT[3] == 1)
GPIOE_PSOR = Display_2D;
else
GPIOE_PCOR = Display_2D;

if((BIT[0] == 0) && (BIT[1] == 0) && (BIT[2] == 0) && (BIT[3] == 0))


GPIOE_PDOR = 0x00000000;

Das könnte Ihnen auch gefallen