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.

Need C program for counting down on 7 segment display

Status
Not open for further replies.

asham

Junior Member level 1
Junior Member level 1
Joined
Jan 24, 2006
Messages
19
Helped
2
Reputation
4
Reaction score
2
Trophy points
1,283
Activity points
1,454
i need a c program that counts from 9 to 0 on the 7 segment display..i'm using mplab ide and p18f4520.. i have created such programs using assembly language but i in c language,i don know much....any help would be appreciated...
 

p18f4520 7 segment display program

here is c code written in mikroc pic compiler.

Code:
//******************************************************************************
// microcontroller : PIC16F84A
//
// Project: 7seg_display1
// This project is designed to work with PIC16F84A;
// with minor adjustments, it should work with any other PIC MCU.
//
// This code demonstrates how to display number on one 7-segment display
// (common cathode).
// Display is connected to portb(RB0..RB7, segment A to RB0,
// segment B to RB1, etc); common cathode is connected to the pin RA1 on porta.
// Number is incremented every 1 second
//******************************************************************************

unsigned short i;

// Function returns mask of num for common cathode 7seg. display
unsigned short Mask_7seg(unsigned short num) {
  switch (num) {
    case 0: return 0x3F;
    case 1: return 0x06;
    case 2: return 0x5B;
    case 3: return 0x4F;
    case 4: return 0x66;
    case 5: return 0x6D;
    case 6: return 0x7D;
    case 7: return 0x07;
    case 8: return 0x7F;
    case 9: return 0x6F;
  }
}//~

void main() {
  INTCON = 0;  // Disable PEIE, INTE, RBIE, T0IE
  TRISA  = 0;
  TRISB  = 0;
  PORTB  = 0;
  PORTA  = 2;

  // Main loop
  do {
    for (i = 0; i <= 9u; i++) {
      PORTB = Mask_7seg(i);  // Display digit on 7seg display
      Delay_ms(1000);        // 1 second pause
    }
  } while (1);
}//~!
 
Re: 7 segment display

thanks veri much..i''ll try it out
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top