View previous topic :: View next topic |
Author |
Message |
stock2
Joined: 28 Jun 2011 Posts: 5 Location: Bangladesh
|
I need ccs c code for seven segment displaying frequency |
Posted: Wed Jul 06, 2011 9:51 am |
|
|
I would really appreciate if somebody can give a complete complete ccs c code to make a frequency counter with three seven segment display for 16f877a. I made one but it doesn't work because i don't understand how to integrate the timer function with the seven segment display. Please somebody help me with this.... i used ex_freq example and could display it in a lcd but seven segment gets me confused.
thanks... |
|
|
bkamen
Joined: 07 Jan 2004 Posts: 1615 Location: Central Illinois, USA
|
|
Posted: Wed Jul 06, 2011 10:13 am |
|
|
There's a lot of examples out there that you can look at.
You can read messages here and see the outpouring of free help given to those who make an honest effort at getting it done themselves.
Heck, I hardly ever post original topics here -- but even I still get stuck every now and then and would like additional opinions or observations from others.
However, usually when you ask someone to completely write something for you to be delivered in a finished form, that person is usually referred to as a consultant or contractor. And they are happy to do it for you at their normal prices.
However, requests to have others do your work for you - for free - are usually frowned upon -- just so you know.
Cheers,
-Ben _________________ Dazed and confused? I don't think so. Just "plain lost" will do. :D |
|
|
bkamen
Joined: 07 Jan 2004 Posts: 1615 Location: Central Illinois, USA
|
|
Posted: Wed Jul 06, 2011 10:17 am |
|
|
So,
Now let's talk about your 7segment display.
Typically, you have outputs from the PIC that either drive the LED segments directly or if you want to save pins, you can use a 7seg driver that usually requires less PIC I/O's.
From there, to handle multiple displays, you simple loop across display 1, then 2, then 3. This could be an ISR (timer) or just stuck in main.
if the CCP is capturing the times (for your frequency measurement) then another ISR like the display running is less of a problem. However, if there's ANY software critical part of measuring the frequency, then another ISR is a bad idea..
Let me find a 7seg decoder... brb _________________ Dazed and confused? I don't think so. Just "plain lost" will do. :D |
|
|
bkamen
Joined: 07 Jan 2004 Posts: 1615 Location: Central Illinois, USA
|
|
Posted: Wed Jul 06, 2011 10:20 am |
|
|
Look at the CD4511 7seg display driver.
Using it would have some advantages over a PIC strobing through the displays (resulting in flickering) where the CD4511 is latched and keeps those segments full on.
Cheers,
-Ben _________________ Dazed and confused? I don't think so. Just "plain lost" will do. :D |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9225 Location: Greensville,Ontario
|
|
Posted: Wed Jul 06, 2011 10:35 am |
|
|
Obvious place to start is to post your code and schematic so we can help.
You're 3 digit 7 segment LED unit may be common anode or common cathode, that makes a HUGE difference.
You don't say what frequency range you need. 1Hz to 100 MHz ?????
We need more specs and your code to help you. |
|
|
stock2
Joined: 28 Jun 2011 Posts: 5 Location: Bangladesh
|
|
Posted: Wed Jul 06, 2011 10:42 am |
|
|
I need a frequency counter not more than 20 khz. I get good reading with the ex_freq example with lcd. But the problem is with seven segment display.
Here is the code > But does not work.
I connected the port b pins b0 to b6 and
for cathode common i connected d7 d6 and d5.
I think it flashes and leaves very fast.
Please help me with this . If you can maybe put the timer func in a function .
thanks,
Code: |
void main() {
int cycles8, cycles;
int32 freq;
long int frek;
int8 hundreds; // hundreds position
int8 tens; // tens position
int8 ones ;
long freqc_high;
long freqc_low;
//set_tris_b(0);
port_b=1;
//begin frew
while (TRUE) {
cycles8=0;
cycles=0;
freqc_high=0;
t1_overflow=0;
set_timer1(0);
setup_timer_1(T1_EXTERNAL|T1_DIV_BY_1);
/* ___ wait one second ___ */
while (cycles!=0xFF) { //true=3, false=4
cycles8=0; //1 cycle
//start inner loop
while (cycles8!=0xFF) { //true=3, false=4
if (t1_overflow)//true=2,false=3 //----|
{t1_overflow=0;freqc_high++;}//6 cycles // |
else // |-- 8 cycles
{delay_cycles(5);} //----|
delay_cycles(62); //x
cycles8++; //1
///2 cycles to jump to top
//math: end inner loop
//math: total inner loop=((3+8+x+1+2)*255 + 4)*255
//math: if x=62.87781 then inner loops takes 5mil instructions
//math: if x=62 then inner loop takes 4942920, have to fill 57080 cycles
}
delay_cycles(216); //y
cycles++; ///1 cycle
///2 cylces to jump to top
//math: outer=(3+1+y+1+2)*255+4=57080
//math: y=(57080-4)/255)-(3+1+0+0+1+2)
//math: if y=216.827450980392156862745098039216 then outer loop cylces is 57080
//math: if y=216 then outer loop cycles is off by 211 cycles. z=211
}
delay_cycles(211); //z
/* ___ end waiting 1 second ___ */
setup_timer_1(T1_DISABLED); //turn of counter to prevent corruption while grabbing value
if (t1_overflow) //check one last time for overflow
freqc_high++;
freqc_low=get_timer1(); //get timer1 value as the least sign. 16bits of freq counter
freq=make32(freqc_high,freqc_low);
//endf freeq
frek=(freq/38);
if
(frek>999);
{frek=0;}
hundreds =(frek/100);
tens = ((frek-hundreds*100)/10);//(temp/10)%(10);
ones=(frek-hundreds*100-frek*10); //(temp%10);
//begin
if (ones==0)
{
port_b=0x3F;}
if (ones==1)
{
port_b=0x06;}
if (ones==2)
{
port_b=0x5B;}
if (ones==3)
{
port_b=0x4F;}
if (ones==4)
{
port_b=0x66;}
if (ones==5)
{
port_b=0x6D;}
if (ones==6)
{
port_b=0x7D;}
if (ones==7)
{
port_b=0x07;}
if (ones==8)
{
port_b=0x7F;}
if (ones==9)
{
port_b=0x6F;}
output_low(PIN_D7);
delay_us(1000);
output_high(PIN_D7);
// display_segs(two);
if (tens==0)
{
port_b=0x3F;}
if (tens==1)
{
port_b=0x06;}
if (tens==2)
{
port_b=0x5B;}
if (tens==3)
{
port_b=0x4F;}
if (tens==4)
{
port_b=0x66;}
if (tens==5)
{
port_b=0x6D;}
if (tens==6)
{
port_b=0x7D;}
if (tens==7)
{
port_b=0x07;}
if (tens==8)
{
port_b=0x7F;}
if (tens==9)
{
port_b=0x6F;}
output_low(PIN_D6);
delay_us(1000);
output_high(PIN_D6);
if (hundreds==0)
{
port_b=0;}
if (hundreds>0)
{
port_b=0x06;}
output_low(PIN_D5);
delay_us(10);
output_high(PIN_D5);
}
} |
|
|
|
stock2
Joined: 28 Jun 2011 Posts: 5 Location: Bangladesh
|
|
Posted: Sat Jul 09, 2011 12:00 am |
|
|
Hi, I found another Hitech code for frequency and seven segment display. Can someone help me convert this into ccs c for pic 16f877a. I really need help in doing this. I am also trying myself for last few days. Thanks
This is for Hi-tech.
Code: |
//---------------------------------------------
// FREQUENCY COUNTER
// www.circuit-projects.com
// Y.Erol
//---------------------------------------------
#include <pic.h>
#include <delay.c>
__CONFIG(WDTDIS&PWRTEN&LVPDIS&XT);
unsigned char kontrol;
//---------------------------------------------
// CCP1 INTERRUPT
//---------------------------------------------
void interrupt interrupt(void){
TMR1H=0; TMR1L=0;
GIE=0;
control=1;
CCP1IF=0;
GIE=1;
}
//---------------------------------------------
// MAIN PROGRAM
//---------------------------------------------
main(void)
{
unsigned const char number[10]={0x3F,0x06,0x5B,
0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F};
unsigned char select[4]={1,2,4,8};
unsigned int counter,value,remainder1,remainder2;
float frekans;
unsigned char a,i,display[5],data;
TRISA=0x00;
TRISB=0x08;
CMCON=0x07;
cont=0;
PORTA=0; PORTB=0
CCP1IE=1;
CCP1CON=0b00000110;
T1CON=0b00100001;
GIE=1;
PEIE=1;
for(;;){
counter=256*CCPR1H+CCPR1L;
if(control==1)frequency=100000000/counter;
if(kontrol==0)frequency=0;
if(counter<10000)frequency=0;
control=0;
for(a=0;a<25;a++){
value=(int)frequency;
display[1]=value/1000;
remainder1=value-display[1]*1000;
display[2]=remainder1/100;
remainder2=remainder1-display[2]*100;
display[3]=remainder2/10;
display[4]=remainder2-display[3]*10;
for(i=0;i<4;i++){
PORTB=0;
PORTA=0;
data=number[display[i+1]];
PORTB=data&0x07;
data=data<<1;
PORTB=PORTB|(data&0xF0);
PORTA=select[i];
DelayMs(3);
}
}
}
} |
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sat Jul 09, 2011 10:35 am |
|
|
Your style of asking questions is wrong. Don't post non-CCS code and
ask us to fix it, and don't go to every tachometer thread and ask for
7-segment code.
Start by posting the manufacturer and part number of your 7-segment
display module. If you have a schematic, then post a link to it.
If you don't have a 7-segment display, then tell us that. If you need help
to choose the correct parts to buy, then tell us.
If this is a Proteus simulator project and you don't intend to buy any
hardware, then tell us that. |
|
|
stock2
Joined: 28 Jun 2011 Posts: 5 Location: Bangladesh
|
|
Posted: Mon Jul 11, 2011 4:37 am |
|
|
sorry for posting h-tech code.
but i posted it as an work example written in hitech. I will not post any other code than ccs-c .
i want a simple frequency meter with seven segment display for ccs-c . |
|
|
dyeatman
Joined: 06 Sep 2003 Posts: 1933 Location: Norman, OK
|
|
Posted: Mon Jul 11, 2011 5:50 am |
|
|
Two things that need to be known:
1. Has the HiTech code you posted been verified work on YOUR
hardware? If not, converting it may not do any good.
2. You need to answer PCMs questions:
Quote: | Start by posting the manufacturer and part number of your
7-segment display module. If you have a schematic, then post a link to it.
If you don't have a 7-segment display, then tell us that. If you need help
to choose the correct parts to buy, then tell us.
If this is a Proteus simulator project and you don't intend to buy any
hardware, then tell us that.
|
_________________ Google and Forum Search are some of your best tools!!!! |
|
|
stock2
Joined: 28 Jun 2011 Posts: 5 Location: Bangladesh
|
|
Posted: Sat Jul 16, 2011 2:54 am |
|
|
Yes the hitech code works. I need it it translated in ccs c code . thanks |
|
|
dyeatman
Joined: 06 Sep 2003 Posts: 1933 Location: Norman, OK
|
|
Posted: Sat Jul 16, 2011 6:48 am |
|
|
I don't think anyone here is going to translate your HiTech code for you but
we can help you get your new CCS code debugged once you write it.
You STILL have not answered PCMs questions!!! _________________ Google and Forum Search are some of your best tools!!!! |
|
|
ERICOO
Joined: 13 Jun 2011 Posts: 14 Location: NIGERIA
|
I need ccs c code for seven segment displaying frequency |
Posted: Wed Jul 27, 2011 4:05 pm |
|
|
Hello Stock2. All that you need do is declare an array of the digits 0 - 9 for example
Code: | char dig_map[10] = {3f, 0x06,0x5b,4f.............0x6f};
|
then
Code: |
void display(){
portb = dig_map[hundred];// display hundredth digit
porta = 4;
portb = dig_map[tens];// display tenth digit
porta = 2;
portb = dig_map[one];// display unit digit
porta = 1;
} |
You will need to call this function in one of the timers interrupt routine. The interrupt should occur every 5 milliseconds. I have written a complete code to display speedometer in my car and it works great. |
|
|
|