Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

pic adc programing problem

Status
Not open for further replies.

suvaraj

Member level 2
Joined
Dec 24, 2010
Messages
50
Helped
4
Reputation
8
Reaction score
4
Trophy points
1,298
Location
erode
Activity points
1,580
hi to all
im using pic microcontroller 16f877a and use ccs c compiler.i have a level sensor and it has 4 levels(each level has different voltages).i need to use one pin for input and 4 leds used for display which level reached.for example if 2v dc come to input means i need 1st level led on then 3v dc come to input means i need 2st level led on etc.... how to i programme in pic c?pls help me
 

#include <16F877.h>
#use delay(clock=4000000)
#fuses NOWDT,XT,NOPUT,NOPROTECT,NOBROWNOUT,NOLVP,NOCPD,NOWRT,NODEBUG
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7,stream=HOSTPC)
void main()
{
int8 value;
int8 adcvalue;
delay_ms(100);
set_tris_b(0x00);
set_tris_d(0xff);
setup_adc(ADC_CLOCK_INTERNAL);//enables the a/d module //and sets the clock to internal adc clock
setup_adc_ports(ALL_ANALOG);
//sets all the adc pins to analog


while(1)

// iput from 8052 to pic is rd5,d6,d7
// the adc value to 8052 from pic is rb port
{

value=input_d();
value=value & 0xe0;
if(value==0x00)
{
set_adc_channel( 0 );
delay_us(10);adcvalue=read_adc();
output_b(adcvalue);
}
if(value==0x20)
{
set_adc_channel( 1 );
delay_us(10);adcvalue=read_adc();
output_b(adcvalue);
}
if(value==0x40)
{
set_adc_channel( 2 );
delay_us(10);adcvalue=read_adc();
output_b(adcvalue);
}
if(value==0x60)
{
set_adc_channel( 3 );
delay_us(10);adcvalue=read_adc();
output_b(adcvalue);
}
if(value==0x80)
{
set_adc_channel( 4 );
delay_us(10);adcvalue=read_adc();
output_b(adcvalue);
}
if(value==0xa0)
{
set_adc_channel( 5 );
delay_us(10);adcvalue=read_adc();
output_b(adcvalue);
}
if(value==0xc0)
{
set_adc_channel( 6 );
delay_us(10);adcvalue=read_adc();
output_b(adcvalue);
}
if(value==0xe0)
{
set_adc_channel( 7 );
delay_us(10);
adcvalue=read_adc();
output_b(adcvalue);
}
}

}
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top