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] Please describe the meaning =mask(digit)

Status
Not open for further replies.

Asanka Lakmal Morawaka

Newbie level 4
Joined
Nov 7, 2014
Messages
5
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
32
portd_array[3] = mask(digit);

Please describe the meaning =mask(digit);
here digit is unsigned integer and Portd_array[3] is an array
I got this from mikeoC code;
 

yes this is a 7 segment display, and it's originally written for PIC18F45k22 but I try to used with 18F4520, when I compile following error(please see the image) comes up.
Code:
#include "Display_Utils.h"

unsigned short shifter, portd_index;
unsigned int   digit, number;
unsigned short portd_array[4];

void interrupt() {
  LATA = 0;                             // Turn off all 7seg displays
  LATD = portd_array[portd_index];      // bring appropriate value to PORTD
  LATA = shifter;                       // turn on appropriate 7seg. display

  // move shifter to next digit
  shifter <<= 1;
  if (shifter > 8u)
    shifter = 1;

  // increment portd_index
  portd_index++ ;
  if (portd_index > 3u)
    portd_index = 0;             // turn on 1st, turn off 2nd 7seg.
  TMR0L  =   0;                  // reset TIMER0 value
  TMR0IF_bit = 0;                // Clear TMR0IF
}

void main() {
  ANSELA = 0;                    // Configure PORTA pins as digital
  ANSELD = 0;                    // Configure PORTD pins as digital

  TRISA = 0;                     // Configure PORTA as output
  TRISC = 0xFF;
  LATA  = 0;                     // Clear PORTA
  TRISD = 0;                     // Configure PORTD as output
  LATD  = 0;                     // Clear PORTD

  T0CON = 0xC4;                  // Set TMR0 in 8bit mode, assign prescaler to TMR0
  TMR0L = 0;                     // clear TMROL
  digit = 0;
  portd_index = 0;
  shifter = 1;

  number = 1234;                 // Initial number value
  GIE_bit = 1;
  TMR0IE_bit = 1;

  do {
    digit =PORTC ;             // extract thousands digit
    portd_array[3] = digit;        // and store it to PORTD array
    /*digit = (number / 100u) % 10u;       // extract hundreds digit
    portd_array[2] = mask(digit);        // and store it to PORTD array
    digit = (number / 10u) % 10u;        // extract tens digit
    portd_array[1] = mask(digit);        // and store it to PORTD array
    digit = number % 10u;                // extract ones digit
    portd_array[0] = mask(digit);        // and store it to PORTD array
      */
    Delay_ms(1000);                      // one second delay

    number++ ;                           // increment number
    if (number > 9999u)
      number = 0;

  } while(1);                            // endless loop
}
Untitled.png
 

Attachments

  • Untitled.png
    Untitled.png
    60.2 KB · Views: 97
Last edited:

The function definition and function prototype of mask() appears in some other file which is not included. Please zip and post the complete project files.
 

I guess that your mask() function is like this

According to this if digit is 7 then case 7 is executed and that is the 7 Segment Mask value to display 7. That value is returned by the function and that is assigned to the & Segment Display Data port.


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
unsigned short mask(unsigned short digit) {
     
    switch (digit) { 
 
        case 0 : return 0xC0; 
 
        case 1 : return 0xF9; 
 
        case 2 : return 0xA4; 
 
        case 3 : return 0xB0; 
 
        case 4 : return 0x99; 
 
        case 5 : return 0x92; 
 
        case 6 : return 0x82; 
 
        case 7 : return 0xF8; 
 
        case 8 : return 0x80; 
 
        case 9 : return 0x90; 
 
    }; 
}
 
 
PORTx = mask(digit);

 
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top