por Hermann Rocha » 11 Jan 2010 19:08
Olá, sei que esta em C mais nao sei qual é o compilador e se esta tudo serto com o codigo.
Grato
//uController used: 16F684.
//This program uses the internal osc, set to 4 Mhz by default. Six LED are connected to
//PortC, RC0 to RC5, and 2 LED are connected to PortA- RA4 and RA5.
//A 10K POT is connected to AN2- the analogue input.
//The first 2 bit of the converted result is not used. We only use AHRESH to store bit 2 to 9.
#include <pic.h>
#include "delay.c"
#include "delay.h"
__CONFIG(WDTDIS & INTIO & PWRTEN & MCLRDIS & UNPROTECT & BORDIS);
//#defineXTL4000000
const char display_portc[]= {0b00000001, 0b00000010, 0b00000100, 0b00001000,
0b00010000, 0b00100000};
const char display_porta[]= {0b00010000, 0b00100000};
main()
{
int ADCresult= 0;
CMCON0 = 7; //Turn off comparators
ANSEL = 0b00000100; //Pin 11- RA2/AN2 as analogue input.
TRISA= 0b00000100; //PortA as output except RA2 as input
TRISC = 0; //PortC as output
//OSCCON= 0b01110101; //This is to set the internal OSC to 8 Mhz
ADCON0= 0b00001001; //Result left justified format, voltage reference= VDD,
//AN2= analogue input, initiates ADC and waiting to start conversion.
ADCON1= 0b00010000; //For 4 Mhz, 8Tosc= 2 uS, which > 1.6 uS, the minimum requirement.
while(1)
{
DelayUs(50); //Wait minimum sample time.
GODONE = 1; //Start conversion.
while(GODONE== 1); //Wait until conversion is done.
ADCresult= ADRESH; //Transfer from ADRESH to ADCresult.
if(ADCresult< 228) PORTA= 0;
if(ADCresult<= 76) PORTC= display_portc[0];
else if(ADCresult<= 102) PORTC= display_portc[1];
else if(ADCresult<= 128) PORTC= display_portc[2];
else if(ADCresult<= 153) PORTC= display_portc[3];
else if(ADCresult<= 179) PORTC= display_portc[4];
else if(ADCresult<= 204) PORTC= display_portc[5];
else if(ADCresult<= 228)
{
PORTA= display_porta[0];
PORTC= 0;
}
else if(ADCresult<= 255) PORTA= display_porta[1];
}
}