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.

how to configured pic16f676 in micro c pro compiler

Status
Not open for further replies.
I am getting confused about the way you have wired the 7 segment displays with the MCU and defined so many against same port bits. However what is the problem? Is it not glowing or showing incorrect value?

Just connect the displays parallel to each other's segments except common anode or cathode. Define these 7 segments as you have done and interface these segments to 7 I/O pins of MCU. Make arrangement to source or sink the common anode or cathode of each 7 segment modules using suitable device e.g. transistor. By multiplexing these modules, required display will be obtained. See the image.

Also you need not to use display() and display_2() functions. Only one function is enough. See the code. without going into the calculation for deriving digits, I have inserted infinite loop only. See what happens. Tell me the result in detail.

Why you have used DP for writing 0-99 by 2 seven segment displays?

Code:
void main() 
{
  int x;
  CMCON = 0x07;
  TRISA= 0x01;
  TRISC  =0x00;
  ANSEL  = 0X01;
  ADCON0=0X81;
  ADCON1=0X30;

     while (1)
         {
          value = ADCON0;
           hun=value/100;
           value=value-hun*100;
           dec=value/10;
                 unit=value-dec*10;
                   cc_1=1;cc_2=0;
                  display();
                  delay_ms(100);
                  cc_1=0;cc_2=1;
                  display2();
                  delay_ms(100);
            }


          }


Try this code

Code:
#define pin_a PORTC.RC5
#define pin_b PORTC.RC4
#define pin_c PORTC.RC0
#define pin_d PORTC.RC3
#define pin_e PORTC.RC1
#define pin_f PORTA.RA4
#define pin_g PORTA.RA5
#define pin_dp PORTC.RC2
#define cc_1 PORTA.RA2
#define cc_2 PORTA.RA1


unsigned char digit,unit,dec,hun,i,j,value=0;

void display()
{
switch(digit)
{
case 0:   pin_a=1;pin_b=1;pin_c=1;pin_d=1;pin_e=1;pin_f=1;pin_g=0;pin_dp=1;
          break;
case 1:   pin_a=0;pin_b=1;pin_c=1;pin_d=0;pin_e=0;pin_f=0;pin_g=0;pin_dp=1;
          break;
case 2:   pin_a=1;pin_b=1;pin_c=0;pin_d=1;pin_e=1;pin_f=0;pin_g=1;pin_dp=1;
          break;
case 3:   pin_a=1;pin_b=1;pin_c=1;pin_d=1;pin_e=0;pin_f=0;pin_g=1;pin_dp=1;
          break;
case 4:   pin_a=0;pin_b=1;pin_c=1;pin_d=0;pin_e=0;pin_f=1;pin_g=1;pin_dp=1;
          break;
case 5:   pin_a=1;pin_b=0;pin_c=1;pin_d=1;pin_e=0;pin_f=1;pin_g=1;pin_dp=1;
          break;
case 6:   pin_a=1;pin_b=0;pin_c=1;pin_d=1;pin_e=1;pin_f=1;pin_g=1;pin_dp=1;
          break;
case 7:   pin_a=1;pin_b=1;pin_c=1;pin_d=0;pin_e=0;pin_f=0;pin_g=0;pin_dp=1;
          break;
case 8:   pin_a=1;pin_b=1;pin_c=1;pin_d=1;pin_e=1;pin_f=1;pin_g=1;pin_dp=1;
          break;
case 9:   pin_a=1;pin_b=1;pin_c=1;pin_d=1;pin_e=0;pin_f=1;pin_g=1;pin_dp=1;
          break;
  }


}






void main() 
{
  int x;
  CMCON = 0x07;
  TRISA= 0x01;
  TRISC  =0x00;
  ANSEL  = 0X01;
  ADCON0=0X81;
  ADCON1=0X30;

    while (1)
         {
          value = Read_ADC( **  );// ADC Channel
           hun=value/100;
           dec =(value/100) % 10;
           unit=value % 10;
           digit = dec;
                   cc_1=1;cc_2=0;
                  display();
                  delay_ms(100);
                  cc_1=1;cc_2=1;
           digit = unit;
                  cc_1=0;cc_2=1;
                  display();
                  delay_ms(100);
                  cc_1=1;cc_2=1;
            }


          }
 
Last edited:
thanku sir i am trying your code in my hardware

- - - Updated - - -

Actually i am trying this on hardware. In that segment pins are not connected in same manner.
HTML:
7 segment 1        7 segment 2         controller
  Seg_a                  Seg_f                      RC5
  Seg_b                  Seg_g                     RC4
  Seg_c                  Seg_d                      RC0
  Seg_d                  Seg_c                      RC3
  Seg_e                  Seg_dp                    RC1
  Seg_f                  Seg_a                      RA4
  Seg_g                  Seg_b                      RA5
  Seg_dp                 Seg_e                     RC2
Thats why i did program in that way.
I am able to display numbers 00-99 using both display.
What i am trying to do is take the value from RA0 as analog value and display it on segments in real number form..... I am using internal osc......
 

You need two different display() routines which uses two different mask values, one for digit 1 and another for digit 2. This is a unnecessary way of connecting the displays. You can use one 8 bit data bus for the two displays and one set of mask values and toggle the common drive pin of the displays alternately.

Instead you are placing two different data on the data bus and toggling the drive pin of display alternately.

If you still need code for your circuit then I can help with a timer interrupt based code which uses two different set of mask values.
 
Pic16f676 has two ports RA and RC and each port have only 6 output/input pins.......I have to do it same manner as i described above.....for now...
 

Do you have to use the same circuit ? Or Shall I besign a better circuit which uses 6 pins of one port and 2 pins of another port with one set of mask values for the two multiplexed displays ?
 
I am looking for example how to take value from ADC, process it and display it on 7 segment.......I also went through datasheet of it but still it not too much clear to me.....if i get some example code of it than i will change it according to my project...

- - - Updated - - -

Yeah....i can also familiar with multiplexing of 7 segments.....but this time i have to use it in same manner as i described......
 

Attachments

  • PIC16Voltmeter.rar
    72.6 KB · Views: 74
I am writing code for your project. Will post it in a few minutes. Wait for sometime.
 

I am trying to display the voltage of AN0 pic on segments 0-5 v......Suppose if it's receiving the voltage 3.5v than i want to show this according to voltage on display....
 
Last edited:

So, you only want adc code ?

Anyway check the attached circuit and tell if you want code for this.
 

Attachments

  • Driving Two Digits 7 Segemnt Display #2.png
    Driving Two Digits 7 Segemnt Display #2.png
    47.5 KB · Views: 106
Last edited:

yes sir i want to code as defined above schematic circuit ,
your schematic circuit is same define as like me hardware circuit .
you are fined my problem.
please tell me code for above schematic circuit.
 

I am a little busy with something. I will post the code for your project by tomorrow. I am now finding out the two sets of mask values for your project.
 

I tried but it says not enough ROM.
 

Just send me ......i want to see your code ,i am intrested how to use method aproches for this project.
 

Mask values not yet calculated.
 

Attachments

  • ADC On 7 Segemnt Display.rar
    48 KB · Views: 69

hi there,
your source code is not compile .it said not enough rom have cotroller,
i try all things but not get output with adc.what should i do?
please guide me sir.
 

i try all things but not get output with adc.what should i do?
please guide me sir.

Have you sorted out the problem ? If you still need code suitable for your existing hardware, try this code. This code occupies nearly 80% of available ROM of 16F676. The code has been tested on 7 segment common anode display. If you use common cathode type, use the mask meant for common cathode type display in the code instead of existing mask for common anode type. The changes to be done has been shown in the code itself. If the display shows reverse number ( such as 4.1 is shown as 1.4) alternate the cc_1 and cc_2 definition accordingly.

Code:
#define pin_a   RC5_bit

#define pin_b  RC4_bit

#define pin_c  RC0_bit

#define pin_d  RC3_bit

#define pin_e  RC1_bit

#define pin_f  RA4_bit

#define pin_g  RA5_bit

#define pin_dp  RC2_bit

#define cc_1  RA2_bit
#define cc_2  RA1_bit

const unsigned char Drive_Segment[10] = {2 , 158, 36, 12, 152, 72, 4, 30, 0,8};
const unsigned char Drive_Segment_1[10] = {72 , 237, 152, 137, 45, 11, 10, 233, 8, 9};

// For common cathode display:
// Drive_Segment[10] = {253, 97, 219, 243, 103, 183, 191, 225, 255, 247}
// Drive_Segment_1[10] = {183, 18, 103, 118, 210, 244, 245, 22, 247, 246}

unsigned char unit,dec,i;
unsigned short  value, SendVal, digit1, digit2;
float voltage, real_value;
unsigned int ad_value;
 void send() {

          pin_dp = SendVal & 1;             // bit 0
        pin_g = (SendVal & 2) >> 1;      // bit 1
        pin_f = (SendVal & 4) >> 2;      // bit 2
       pin_e = (SendVal & 8) >> 3;      // bit 3
        pin_d = (SendVal & 16) >> 4;     // bit 4
        pin_c = (SendVal & 32) >> 5;     // bit 5
        pin_b = (SendVal & 64) >> 6;     // bit 6
        pin_a = (SendVal & 128) >> 7;     // bit 7
        }


void main()
{
  CMCON = 0x07;
  TRISA= 0x01;
  TRISC  =0x00;
  ANSEL  = 0X01;

PORTA = 0xFF;
PORTC = 0xFF;

 // For common cathode display:
//PORTA = 0x00;
//PORTC = 0x00;

delay_ms(500);

 do {
 ad_value = ADC_read(0);
 voltage = (float) ((float) ad_value * .00488);
real_value = (float) voltage;
 

 value = real_value * 10;
 dec = (char)value/10;
 unit = (char)value%10;
 digit1 = (char)Drive_Segment [dec];
 digit2 = (char)Drive_Segment_1 [unit];
 for (i = 0; i< 10; i++) {
 SendVal = digit1;
 send();
 cc_1 = 0;
 cc_2 = 1;
 // For common cathode display:
 //cc_1 = 1;
 //cc_2 = 0;
 
 
 delay_ms(2);
 cc_1 = 1;
 cc_2 = 1;
 
 // For common cathode display:
 //cc_1 = 0;
 //cc_2 = 0;

 SendVal = digit2;
 send();
 cc_1 = 1;
 cc_2 = 0;
 
 // For common cathode display:
 //cc_1 = 0;
 //cc_2 = 1;
 
 delay_ms(2);
 cc_1 = 1;
 cc_2 = 1;
 // For common cathode display:
 //cc_1 = 0;
 //cc_2 = 0;
                     }

           } while (1);
       
       }
 
  • Like
Reactions: SHADIQUE

    SHADIQUE

    Points: 2
    Helpful Answer Positive Rating
    V

    Points: 2
    Helpful Answer Positive Rating
Hello everyone,
i am new in pic controller programming.
I am doing a project on PIC16f72 and using mikroc pro compiler.
The problem i am facing is, according to datsheet of PIC16f72 the value of config word should be 0x3fb2 in case of external osc(4 Mhz).
i have tried every option of config word setting but still didn't get that value of config word...
It seems me that's why i am even not able to blink a led through micro.
Please help me to overcome from this situation and suggest possible way to sort out it.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top