Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

help with pic16f877 and c

Status
Not open for further replies.

kennyburns

New Member
hey i have a small project that i need to finish and im having hard time with the c programming.

i have a pic16f877 and need to read a value from a pot that will give 7 set values then i have to convert the analogue signal fromt he pot into digital and display on a 7 segment LED display A number from 0-6

i will have to use the 10 bit adc for me to be able to seperate the voltages into the groups i want

so we have 0-5 volts and 0-1023 steps

so the program would have to group the numbers like this:
no== voltage== no adc=======binary
--------------------------------------------------------------
1 == 0.06v== 0 =< >=13------
2 == 0.08v== 14=< >=17
3 == 0.10v== 18=< >=21
4 == 0.13v== 22=< >=27
5 == 0.16v== 28=< >=33
6 == 0.17v== 34=< >=36
0 == 4.97v== 37=< >=1023

the analogue input will go on the RA0/AN0 pin no 2
the 7 seg LED will be driven by RB0 - RB7 or port B pins from 33-40

ground would be connected to VDD or pin 11
and +5v to vss or pin 12

could a kind soul that i will be forever greatfull to, give me some help because im starting to loose my mind with c programming
:/
 
If you read the ADC into a variable called volts then something like this should work,
Code:
        if(volts<14)
            num=1;
        else if(volts<18)
            num=2;
        else if(volts<22)
            num=3;
        else if(volts<28)
            num=4;
        else if(volts<34)
            num=5;
        else if(volts<37)
            num=6;
        else
            num=0;

Mike.
 
thnx mate that was lepfull but my problem is how to set the adc to 10 bit
i dont know the instructions very well and from there how to control the 7 segment
 
#include "16f877.h"
#device ADC=8
#use delay(clock=4000000)
#use fast_io(B)
void main(void)
{
set_tris_b(0);
setup_adc_ports(ALL_ANALOG);
setup_adc(ADC_CLOCK_DIV_8);
set_adc_channel(5);
while(1)
{
output_b(read_adc()); //read data
delay_us(20);
}

}

would this do the job?
im a bit worried about that clock thing do i need to put that delay or can i leave it ?
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top