WhyWhy
Member level 4
- Joined
- Mar 18, 2013
- Messages
- 68
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,286
- Activity points
- 1,779
Hi guys,
i had connect the circuit as the picture, but i connect the RA0 with a infrared receiver ,and the RD7 for the Infrared transmitter and all the each PORTB has one led. I put the infrared very close to each other, it still nothing happen. My programming got error? Please help. Thanks
i had connect the circuit as the picture, but i connect the RA0 with a infrared receiver ,and the RD7 for the Infrared transmitter and all the each PORTB has one led. I put the infrared very close to each other, it still nothing happen. My programming got error? Please help. Thanks
Code:
#include<htc.h>
#include<pic.h>
#include "delay.h"
__CONFIG(0x3F3A);
void ADC_Init()
{
ADCON0 = 0x41; //ADC Module Turned ON and Clock is selected
ADCON1 = 0xC0; //All pins as Analog Input
//With reference voltages VDD and VSS
}
unsigned int ADC_Read(unsigned char channel)
{
if(channel > 7) //If Invalid channel selected
return 0; //Return 0
ADCON0 &= 0xC5; //Clearing the Channel Selection Bits
ADCON0 |= channel<<3; //Setting the required Bits
DelayUs(5); //Acquisition time to charge hold capacitor
while(GODONE==1); //Wait for A/D Conversion to complete
return ((ADRESH<<8)+ADRESL); //Returns Result
}
void main()
{
unsigned int a;
TRISB = 0x00; //PORTB as output
TRISC = 0x00; //PORTC as output
TRISA = 0xFF; //PORTA as input
ADC_Init(); //Initializes ADC Module
TRISD=0x00;
PORTD=0xFF;
do
{
a = ADC_Read(0); //Reading Analog Channel 0
PORTB = a; //Lower 8 bits to PORTB
PORTC = a>>8; //Higher 2 bits to PORTC
DelayUs(5); //Delay
}while(1); //Infinite Loop
}