// 14-01-2014
// Project : 16F877_Irdaboard_ADC.mcppi
// PIC16F877 sur carte Microchip IRDA Demo Board 1 102-00032
// Q=20MHz
// CONFIG :$2007 : 0x3B3A
// uses library string,uart,
sbit Led_Verte_D0 at RD0_bit ;
sbit Led_Verte_D1 at RD1_bit ;
// 12345678901234567890
char ConvTable[6];
char CRam1[32];
unsigned char uart_rd;
unsigned int i,j,k,m;
unsigned long L1;
unsigned int Fan,Speed;
void Tempo(unsigned long LT);
void CRLF(void);
void Tempo(unsigned long LT)
{
while (LT-->0);
}
void CRLF()
{
UART1_Write(13);
UART1_Write(10);
}
void main()
{
ADCON1=0x0E;
TRISA=0b11110001 ;
ADCON1=0x0E; // RA0=Analog other as digital portA
TRISC=0b10111111 ;
TRISD=0b00000000 ;
TRISB=0b11110000 ;
PORTB=0;
OPTION_REG=128 ;
PORTA=0;
Led_Verte_D1=1;
Tempo(10000L);
UART1_Init(9600); // Initialize UART module at 9600 bps
Delay_ms(500); // Wait for UART module to stabilize
UART1_Write_Text("16F877 Test string\r\n");
L1=Get_Fosc_kHz();
UART1_Write_Text("Freq kHz= ");
LongToStr(L1, CRam1);
UART1_Write_Text(CRam1);
CRLF();
strcpy(CRam1,"Fan 0 speed: xxxxx RPM");
UART1_Write_Text(CRam1);
CRLF();
ADC_Init();
Led_Verte_D1=0;
Fan=0;
do
{
//Speed m=ADC_Get_Sample(0);
// WordToStr(Speed,ConvTable);
//UART1_Write(9); // tabulation
Speed= 980*Fan;
CRam1[4]=Fan+48; // update fan number
WordToStr(Speed,CRam1+13);
CRam1[18]=32; // replace the zero given by WordToStr by a space
UART1_Write_Text(CRam1);
CRLF();
Led_Verte_D1=!Led_Verte_D1;
Tempo(150000L);
Fan++;
}
while (Fan<10);
do
{}
while(1);
}