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.

Pic controlled channel change and led & 7 segment display 0-99

Status
Not open for further replies.
Hi Don, VK3YV,

Just change a few lines of source code in the "v2" program to implement channel rollover from 99 to 01 (turning clockwise) or from 01 to 99 (turning anti-clockwise);

Code:
  while(1)
  { if(upswitch)                // if "up" switch pulse
    { upswitch = 0;             //   clear the switch flag and
      if(channel < 99)          //   if less than upper limit 99
        channel++;              //     increment "channel"
      else                      //   otherwise
        channel = 1;            //     rollover from 99 to 01
    }
    if(dnswitch)                // if "dn" switch pulse
    { dnswitch = 0;             //   clear the switch flag and
      if(channel > 1)           //   if greater than lower limit 01
        channel--;              //     decrement "channel"
      else                      //   otherwise
        channel = 99;           //     rollover from 01 to 99
    }
The other features you want are relatively easy too. I would recommend using a regular normally-open push button switch for the simplex/duplex/reverse "mode" function. Press the push button once to go from "simplex" to "duplex" ("tens" digit decimal point lighted), press it again to go from "duplex" to "reverse" ("ones" digit decimal point lighted), press it again to go from "reverse" to "simplex" (both decimal points off). Program would ignore the push button when outside the channel 1 through 8 range. This is where one of those rotary encoders with a built-in push button switch on the shaft might be kind of neat (all functions on a single control knob).

The simplex/duplex/reverse logic is relatively simple (example below) but let me study the best way to implement the hardware and software changes for awhile.

Regards...

Code:
  while(1)
  { if(upswitch)                // if "up" switch pulse
    { upswitch = 0;             //   clear the switch flag and
      if(channel < 99)          //   if less than upper limit 99
        channel++;              //     increment "channel"
      else                      //   otherwise
        channel = 1;            //     rollover from 99 to 01
    }
    if(dnswitch)                // if "dn" switch pulse
    { dnswitch = 0;             //   clear the switch flag and
      if(channel > 1)           //   if greater than lower limit 01
        channel--;              //     decrement "channel"
      else                      //   otherwise
        channel = 99;           //     rollover from 01 to 99
    }

    tens = channel / 10;        // display "tens", 0..9
    ones = channel % 10;        // display "ones", 0..9

    if(modesw)                  // if mode push button press
    { modesw = 0;               //   clear the switch flag and
      mode++;                   //   increment "mode" var'
      if(mode == 3)             //   if upper limit 2
        mode = 0;               //     rollover to 0
    }

    if(channel > 8)             // if outside channel 1..8 range
      mode = 0;                 //   force "mode" to 'simplex'

    if(mode == 0)               // if "simplex" mode
      eprom = tens << 4;        //   eprom = 0x01..0x99
    if(mode == 1)               // if "duplex" mode
      eprom = 0x50;             //   eprom = 0x51..0x58
    if(mode == 2)               // if "reverse" mode
      eprom = 0x60;             //   eprom = 0x61..0x68
    eprom += ones;              //

    if(polarity)                // if polarity jumper off (hi)
      portc = eprom;            //   normal eprom address data
    else                        // if polarity jumper on (lo)
      portc = ~eprom;           //   invert eprom address data
  }
}
 
Last edited:
Hi Mike, you make it look so simple, I have printed it out so that I can study it. It is amazing how looking at the code now knowing what is happening that some of it actually makes sense. The polarity jumper was one thing I forgot to put on and it soon showed on the BCD display. I take it that the code you have written is in assembler, it doesn't look like any "C" I have seen and am I right in assuming those channel numbers refered to are in hex as they are below 10.
The PICkit 2 should arrive tomorrow so I will wait and see what comes in the package before I start to try and organise a second Windows system that I have here (AMD64x2, 1gb ram and a 30 Gig drive) should do the job. I will initially concentrate on the 16f886 and what ever the current replacement for the 16f84 is and learn that although the training lessons use a 12f509 and later sessions use a 16f887 so I will get a couple of these for the exersise.
Well its 1.30 am but not so hot in the house tonight , so off to try and get the sleep I missed last night.
Thanks,
Regards,
Don....VK3YV....
 
Hi Mike, everything has finally arrived after the starter kit was delivered 200KM from here and had to be shipped back to Melbourne and was delivered here today along with the 28 pin demo Kit for the PICkit 2. Have been trying to compile the ver 2.c source file with no success, it partially works and then goes beserk. On powerup it looks OK but if you turn the channel knob backwards it immeadiatly locks up and there is no led display and the BCD comes up with junk, if you repower it and you turn the knob forwards it goes up to 8 then jumps to 19 on the next position the the further up you go the led display starts flashing quickly and then stops displaying anything, in the mean time the BCD is diplaying junk and finally locks with a letter A displayed. I know It is probably my fault but is there any chance of there being a difference in which program version you created the .hex file that works fine, ver1 or ver2. Sorry to be such a nuisance but being a newbie I could be going around in circles. I can't grasp how you can mix Assembler and C in the one program, how do you treat that when it comes to compile it?
Many thanks,
Don...
 
Oops! Please locate the following line in the "v2" source code;
Code:
  ones = channel - tens;      // display "ones", 0..9
and change it to this;
Code:
  ones = channel % 10;        // display "ones", 0..9
Recompile to generate a new hex file.

My apologies Don!

The "v2" software contains no assembler code. It's all C code.

Regards, Mike
 
Last edited:
Hi Mike, all is now well, I also added the roll around at each extreme and it works fine too.
Today I will setup the PICkit 2, it looks good and buying the 28 pin development kit was a good idea as I now get an extra 16f886 and the development board plus 2 more blank boards. The PICkit 2 came with a 20 pin development board along with a 16f690 so I have a bit of work ahead of me, but it is satisfying as to how things are falling into place and the knowledge is starting to stir the brain into action again HI.
CUL,
73's Don.....
 
Hi Don,

How's it goin'? Are you ready to move on and implement some of the other features (display leading zero suppression, simplex/duplex/reverse "mode" switch, and display decimal points)?

Regards, Mike
 
Hi Mike, sure am I have been organising my self and have so much material around me now it will take a fair while to digest it all, but its not as daunting as it was a couple of weeks ago. I have the PICkit in the system now and have compiled the program from both MPLAB and Sourceboost successfully after a couple of mistakes, one when I cut and pasted the file from here to the compiler I didn't copy correctly when highlighting the file I missed the last parenthisis of the file and got an error and also in the copy that you altered there was a stray bracket in the altered code but was able to spot it after looking at the error message from the compiler and fixed them and hey presto it worked exactly as it was intended, thank you. So now I feel a lot more confident in the easy part of the process and have done some reading of the info that I have, but on that score there is a long way to go. Will order a few PICs of the types used in the manual that I will use to learn from by "Gooligum" it seems to get good reviews and recomendations, and it is very easy to understand, so here goes . In between sessions I will lay out the board for the final project, make it, and fit it to the radio.
So I'm ready to go with whatever you suggest.
Regards,
Don....
 
Last edited:
Ok then, do you want to use that center-off DPDT switch using two PIC pins (RA5 and RA4) or do you want to try a simple push button switch using one PIC pin (RA5)? Just let me know which way you want to go and I will code accordingly.

For the display decimal points, why don't you connect them to RA2 for now.

I will start a new "v3" source file with the code changes and post that and the hex file for you later today.

Kind regards, Mike, K8LH
 
Hi Mike. I think the SPDT switch would be the best as it doesn't need to have to look at the radio whilst driving, and on a bright sunny day the DP may not be all that visible without taking your eyes off the road to focus on the radio ( I wear Trifocals) and the switch is a definate up or down movement. So go for it, and I will modify my end to suit the pins you suggested.
Thanks , Don......
 
Ok Don. The reasoning behind your decision is sound and I will add code to handle the SPDT switch connected to RA4 and RA5 pins. Please connect switch common to ground and add pull-up resistors to RA4 and RA5.

I thought the push button might be the better way to go but I admit I may have been thinking too far ahead. I thought it might be nice to automatically set the "mode" for each channel (1 through 8) from a "memory" as you select the channel. Then "short" push button presses would over-ride the "memory" to select a new mode (simplex, duplex, or reverse) and a "long" press could be used to store the current channels "mode" setting to the channels "memory".

Look for the first draft of "v3" source code sometime within the next 12 hours.

Kind regards, Mike, K8LH
 
Last edited:
Here is preliminary (untested) "v3" source file...

Code:
/********************************************************************
 *                                                                  *
 *  Project: Channel Selector                                       *
 *   Source: Channel_Selector_v3.c                                  *
 *   Author: Mike McLaren, K8LH                                     *
 *     Date: 16-Feb-10                                              *
 *  Revised: 26-Feb-10                                              *
 *                                                                  *
 *  OEM 16F886 2-Digit 01-99 Channel Selector                       *
 *                                                                  *
 *                                                                  *
 *      IDE: MPLAB 8.14 (tabs = 4)                                  *
 *     Lang: SourceBoost BoostC v6.95, Lite/Free version            *
 *                                                                  *
 *                                                                  *
 ********************************************************************/

#include <system.h>

#pragma DATA _CONFIG1, _LVP_OFF & _MCLRE_OFF & _WDT_OFF & _INTOSCIO
#pragma DATA _CONFIG2, _BOR40V

//--< function prototypes >------------------------------------------
//--< typedef and defines >------------------------------------------

typedef unsigned char u08;
typedef unsigned int u16;

#define r08 const rom unsigned char

#define upswitch flags.7        // debounced "up" switch flag
#define dnswitch flags.6        // debounced "dn" switch flag

#define duplex swold.5          // debounced "duplex" toggle switch
#define reverse swold.4         // debounced "reverse" toggle switch
#define simplex (!duplex && !reverse)

#define polarity flags.0        // eprom "polarity" jumper

//--< variables >----------------------------------------------------

u08 swnew = 0;                  // switch sample var'
u08 swold = 0;                  // switch state latch
u08 flags = 0;                  // switch press flags

u08 tens;                       // display "tens"
u08 ones;                       // display "ones"
u08 eprom;                      // packed bcd eprom address
u08 channel = 1;                // channel, 01..99

r08 segdata[] = { 0b00111111,   // "0"   -|-|F|E|D|C|B|A
                  0b00000110,   // "1"   -|-|-|-|-|C|B|-
                  0b01011011,   // "2"   -|G|-|E|D|-|B|A
                  0b01001111,   // "3"   -|G|-|-|D|C|B|A
                  0b01100110,   // "4"   -|G|F|-|-|C|B|-
                  0b01101101,   // "5"   -|G|F|-|D|C|-|A
                  0b01111101,   // "6"   -|G|F|E|D|C|-|A
                  0b00000111,   // "7"   -|-|-|-|-|C|B|A
                  0b01111111,   // "8"   -|G|F|E|D|C|B|A
                  0b01101111 }; // "9"   -|G|F|-|D|C|B|A


//--< main >---------------------------------------------------------

void main()
{
  ansel = 0;                    // ANS0..ANS7 ADC inputs off
  anselh = 0;                   // ANS8..ANS13 ADC inputs off
  osccon = 0b01110000;          // set INTOSC to 8 MHz
  while(!osccon.HTS);           // wait 'til oscillator stable
  trisc = 0b00000000;           // set all PORTC pins to outputs
  trisb = 0b00000000;           // set all PORTB pins to outputs
  trisa = 0b11110001;           // RA7..RA4 and RA0 = inputs
  porta = 0b00000000;           // set all output latches to '0'
  portb = 0b00000000;           // set all output latches to '0'
  porta = 0b00000000;           // set all output latches to '0'

//  setup Timer 2 for 8 msec interrupts (8 MHz clock)

  tmr2 = 0;                     // clear Timer 2 register
  t2con = 0b00011110;           // '0-------' unimplemented bit
                                // '-0011---' TOUTPS<3:0>, postscale 4
                                // '-----1--' TMR2ON, turn Timer 2 on
                                // '------10' T2CKPS<1:0>, prescale 16
  pr2 = 250-1;                  // 250 x 32-usec 'ticks' = 8 msecs
  pir1 = 0;                     // clear peripheral interrupt flags
  pie1.TMR2IE = 1;              // set Timer 2 interrupt enable bit
  intcon = 0b11000000;          // '1-------' GIE, enable global ints
                                // '-1------' PEIE, enable peripheral ints
                                // '--0-----' T0IE, TMR0 ints disabled
                                // '---0----' INTE, off
                                // '----0---' GPIE, IOC disabled
                                // '-----000' T0IF/INTF/GPIF flags

//  main program loop

  while(1)
  { if(upswitch)                // if "up" switch pulse
    { upswitch = 0;             //   clear the switch flag and
      if(channel < 99)          //   if less than upper limit 99
        channel++;              //     increment "channel"
      else                      //   otherwise
        channel = 1;            //     rollover from 99 to 01
    }
    if(dnswitch)                // if "dn" switch pulse
    { dnswitch = 0;             //   clear the switch flag and
      if(channel > 1)           //   if greater than lower limit 01
        channel--;              //     decrement "channel"
      else                      //   otherwise
        channel = 99;           //     rollover from 01 to 99
    }

    tens = channel / 10;        // display "tens", 0..9
    ones = channel % 10;        // display "ones", 0..9

    if(channel > 8)             // if outside 01..08 channel range
    { duplex = 0;               // clear "duplex" switch latch
      reverse = 0;              // clear "reverse" switch latch
    }
    if(simplex)                 // if "simplex" mode
      eprom = tens << 4;        //   eprom = 0x01..0x99
    if(duplex)                  // if "duplex" mode
      eprom = 0x50;             //   eprom = 0x51..0x58
    if(reverse)                 // if "reverse" mode
      eprom = 0x60;             //   eprom = 0x61..0x68
    eprom += ones;              //

    if(polarity)                // if polarity jumper off (hi)
      portc = eprom;            //   normal eprom address data
    else                        // if polarity jumper on (lo)
      portc = ~eprom;           //   invert eprom address data
  }
}

/********************************************************************
 *  ISR - refresh display and switch flags (62.5 Hz refresh rate)   *
 ********************************************************************/

void interrupt()                // 8-msec timer 2 interrupts
{ pir1.TMR2IF = 0;              // clear timer 2 interrupt flag
  portb &= 0x80;                // blank the display
  porta.2 = 0;                  // turn off decimal point
  portb ^= 0x80;                // toggle digit select pin (RB7)
  if(portb.7)                   // if 'tens' digit selected and
  { if(tens)                    //   if not leading zero
      portb |= segdata[tens];   //     display "tens", 1..9
    if(duplex)                  //   if "duplex" mode
      porta.2 = 1;              //     turn on decimal point
  }
  else                          // if 'ones' digit selected
  { portb |= segdata[ones];     //   display "ones" digit, 0..9
    if(reverse)                 //   if "reverse" mode
      porta.2 = 1;              //     turn on decimal point
  }
  swnew = ~porta;               // sample active low switches
  swnew &= 0b11110001;          // on RA7..RA4, and RA0 pins
  swnew ^= swold;               // changes, hi or lo
  swold ^= swnew;               // update switch state latch
  swnew &= swold;               // filter out "new lo" bits
  flags |= swnew;               // save "new hi" flag bits
}
<added>
updated source to set RA4 as an input...
 
Last edited:
Hi Mike, a report on the ver3.c program.
The 1 to 8 channels have 60 added all the time, all other channels ok except I cant get 1 - 8. I am using RA4 and RA5 as you first suggested and on measuring RA4 it is hard low as is RA3 with nothing connected to them. Tried 2 new chips, and checked the setup for shorts. The decimal points, the ONES is ok but the TENS flashes, probably because of the cathode driver for the tens having to operate to activate the ones in the multiplexing.
All other aspects are working great, leading zero blanking, the change from duplex once passing 8, or 1 in the other direction , the channel rollover at the ends, all are fine.
A comment about the RA5 and RA6 you mentioned in your second note is that a mistake as RA6 is already used with the channel selector. Secondly you mentioned memory, I dont really want to have memory channels as such but is there anyway of it remembering the channel it was on when powering it off.
Leave you with it Mike,
Thanks Don....
 
Hi Mike, I fixed it all. I got game and over a cup of coffee was reading your code and from what little I have gathered so far I noticed in main where you were setting the ports I noticed that RA4 was set as an output (0) so I became very brave and changed it to an input (1) as it was the bit that was stuck low, yet it was supposed to be reading the Duplex and Reverse switch so needed to be an input, I then re-compiled it and programmed another PIC and put it in, and stood back and switched it on and it worked in all aspects D.P. and all. Its "GREAT". You have done a superb job and I am in your debt.
I will talk to you later.
Thanks, Don......
 
Hey Don,

You did it! You found and fixed the 'bug' in the program. I'm very happy that you're happy Sir.

I wrote "v3" software for a single push button and then went back and modified it for the toggle switch but I forgot to make that one change to make RA4 an input, as you figured out. I actually fixed a couple things in that program and updated the listing a few minutes ago (the RA4 fix, deleted unused variables, etc.) so you might want to collect a fresh copy of it from post #51.

Saving the last selected channel as power-up default? I need to think about that. Any ideas fellow Forum members?

Regards, Mike, K8LH
 
Last edited:
Hi Mike, there is no panic on the last selected channel power up default, thought I had on that was to leave the unit running when the rest was turned off , but how to kill the LED display stumpt me. I dont think the power drain of the unit without the LED segments would ever worry the battery. I have had a play around with something I thought might not be too hard but it didn't work, and that was to limit the number of channels in simplex to 40 and retain all of the other features, it wasn't as simple as changing the references to 99 to 40 but it was worth a try Hi. This is becoming the most fascinating thing I have done for a long time Mike, thank you. I'll go and try the new version now.
Thanks, Don....
 
I have had a play around with something I thought might not be too hard but it didn't work, and that was to limit the number of channels in simplex to 40 and retain all of the other features, it wasn't as simple as changing the references to 99 to 40 but it was worth a try Hi.
Actually, changing the two '99' values to '40' should have worked. Did you re-compile and use the new 'hex' file?

This is becoming the most fascinating thing I have done for a long time Mike...
I remember that feeling and still experience it all the time. Welcome to a wonderful and exciting new adventure Don.

Kind regards, Mike, K8LH
 
Don,

Just noticed a potential problem in that code where the eprom address output might get corrupted for a short 8-msec period if one of our 8-msec interrupts occurs within a certain section of code. Let me fix that and post the changes shortly. Sorry for the inconvenience.

Mike
 
Hi again Mike, ok the problem (possible) . I have just done the 40 ch mod and it works fine I think I changed all occurences of 99 not just the 2 at the start of the main loop. That gives the whole exersise another dimension for many other applications, the mind boggles. I may not get a chance to try the next version for about 5 or 6 days as my daughter Karen is about to have my 2nd grandson and I have just received a call to say it could be as soon as Sunday but will all be over Wednesday ready or not. Original date was March 20 then the 12th and now 28th Feb, and I will have to head off to Melbourne tomorrow morning about 11 am, a 275KM drive from here (3.5hrs). But if the progam is here when I wake in the morning I will try it and drop you a note, can almost do it while the toast is cooking now, its so easy. I will restablish contact when I get back, probably Friday or Saturday.
73's Don...
 
Don,

Best wishes and congrats' to your daughter and you Sir.

I'm not going to rush then. Will take my time and do it right.

Yes, lots and lots of possibilities with these microcontrollers. Tell me when you're ready to add the CTCSS tone encoder algorithm (LOL)...

Take care, Mike
 
Don, here is revised "v3" source file.

Regards, Mike, K8LH

Code:
/********************************************************************
 *                                                                  *
 *  Project: Channel Selector                                       *
 *   Source: Channel_Selector_v3.c                                  *
 *   Author: Mike McLaren, K8LH                                     *
 *     Date: 16-Feb-10                                              *
 *  Revised: 25-Feb-10                                              *
 *                                                                  *
 *  OEM 16F886 2-Digit 01-99 Channel Selector                       *
 *                                                                  *
 *                                                                  *
 *      IDE: MPLAB 8.14 (tabs = 4)                                  *
 *     Lang: SourceBoost BoostC v6.95, Lite/Free version            *
 *                                                                  *
 *                                                                  *
 ********************************************************************/

#include <system.h>

#pragma DATA _CONFIG1, _LVP_OFF & _MCLRE_OFF & _WDT_OFF & _INTOSCIO
#pragma DATA _CONFIG2, _BOR40V

//--< function prototypes >------------------------------------------
//--< typedef and defines >------------------------------------------

typedef unsigned char u08;
typedef unsigned int u16;

#define r08 const rom unsigned char

#define upswitch flags.7        // debounced "up" switch flag
#define dnswitch flags.6        // debounced "dn" switch flag

#define duplex swold.5          // debounced "duplex" toggle switch
#define reverse swold.4         // debounced "reverse" toggle switch

#define tensdp swold.1          // tens decimal point flag
#define onesdp swold.2          // ones decimal point flag

#define polarity flags.0        // eprom "polarity" jumper

//--< variables >----------------------------------------------------

u08 swnew = 0;                  // switch sample var'
u08 swold = 0;                  // switch state latch
u08 flags = 0;                  // switch press flags

u08 tens;                       // display "tens"
u08 ones;                       // display "ones"
u08 eprom;                      // packed bcd eprom address
u08 channel = 1;                // channel, 01..99

r08 segdata[] = { 0b00111111,   // "0"   -|-|F|E|D|C|B|A
                  0b00000110,   // "1"   -|-|-|-|-|C|B|-
                  0b01011011,   // "2"   -|G|-|E|D|-|B|A
                  0b01001111,   // "3"   -|G|-|-|D|C|B|A
                  0b01100110,   // "4"   -|G|F|-|-|C|B|-
                  0b01101101,   // "5"   -|G|F|-|D|C|-|A
                  0b01111101,   // "6"   -|G|F|E|D|C|-|A
                  0b00000111,   // "7"   -|-|-|-|-|C|B|A
                  0b01111111,   // "8"   -|G|F|E|D|C|B|A
                  0b01101111 }; // "9"   -|G|F|-|D|C|B|A


//--< main >---------------------------------------------------------

void main()
{
  ansel = 0;                    // ANS0..ANS7 ADC inputs off
  anselh = 0;                   // ANS8..ANS13 ADC inputs off
  osccon = 0b01110000;          // set INTOSC to 8 MHz
  while(!osccon.HTS);           // wait 'til oscillator stable
  trisc = 0b00000000;           // set all PORTC pins to outputs
  trisb = 0b00000000;           // set all PORTB pins to outputs
  trisa = 0b11110001;           // RA7..RA4 and RA0 = inputs
  porta = 0b00000000;           // set all output latches to '0'
  portb = 0b00000000;           // set all output latches to '0'
  porta = 0b00000000;           // set all output latches to '0'

//  setup Timer 2 for 8 msec interrupts (8 MHz clock)

  tmr2 = 0;                     // clear Timer 2 register
  t2con = 0b00011110;           // '0-------' unimplemented bit
                                // '-0011---' TOUTPS<3:0>, postscale 4
                                // '-----1--' TMR2ON, turn Timer 2 on
                                // '------10' T2CKPS<1:0>, prescale 16
  pr2 = 250-1;                  // 250 x 32-usec 'ticks' = 8 msecs
  pir1 = 0;                     // clear peripheral interrupt flags
  pie1.TMR2IE = 1;              // set Timer 2 interrupt enable bit
  intcon = 0b11000000;          // '1-------' GIE, enable global ints
                                // '-1------' PEIE, enable peripheral ints
                                // '--0-----' T0IE, TMR0 ints disabled
                                // '---0----' INTE, off
                                // '----0---' GPIE, IOC disabled
                                // '-----000' T0IF/INTF/GPIF flags

//  main program loop

  while(1)
  { if(upswitch)                // if "up" switch pulse
    { upswitch = 0;             //   clear the switch flag and
      if(channel < 99)          //   if less than upper limit 99
        channel++;              //     increment "channel"
      else                      //   otherwise
        channel = 1;            //     rollover from 99 to 01
    }
    if(dnswitch)                // if "dn" switch pulse
    { dnswitch = 0;             //   clear the switch flag and
      if(channel > 1)           //   if greater than lower limit 01
        channel--;              //     decrement "channel"
      else                      //   otherwise
        channel = 99;           //     rollover from 01 to 99
    }

    tens = channel / 10;        // display "tens", 0..9
    ones = channel % 10;        // display "ones", 0..9

    eprom = tens << 4 + ones;   // packed BCD eprom address

    if(channel > 8)             // if channel > 8
    { tensdp = 0;               //   clear tens 'dp' flag
      onesdp = 0;               //   clear ones 'dp' flag
    }                           //
    else                        // if channel 1-8
    { if(duplex)                //   if "duplex" mode
      { eprom += 0x50;          //     eprom = 0x51..0x58
        tensdp = 1;             //     set tens 'dp' flag
      }
      if(reverse)               //   if "reverse" mode
      { eprom += 0x60;          //     eprom = 0x61..0x68
        onesdp = 1;             //     set ones 'dp' flag
      }
    }                           //

    if(polarity)                // if polarity jumper off (hi)
      portc = eprom;            //   normal eprom address data
    else                        // if polarity jumper on (lo)
      portc = ~eprom;           //   invert eprom address data
  }
}

/********************************************************************
 *  ISR - refresh display (62.5-Hz) and sample switches/jumpers     *
 ********************************************************************/

void interrupt()                // 8-msec timer 2 interrupts
{ pir1.TMR2IF = 0;              // clear timer 2 interrupt flag
  portb &= 0x80;                // blank the display
  porta.2 = 0;                  // turn off decimal point
  portb ^= 0x80;                // toggle digit select pin (RB7)
  if(portb.7)                   // if 'tens' digit selected and
  { if(tens)                    //   if not leading zero
      portb |= segdata[tens];   //     display "tens", 1..9
    if(tensdp)                  //   if tens 'dp' flag
      porta.2 = 1;              //     turn on decimal point
  }
  else                          // if 'ones' digit selected
  { portb |= segdata[ones];     //   display "ones" digit, 0..9
    if(onesdp)                  //   if ones 'dp' flag
      porta.2 = 1;              //     turn on decimal point
  }
  swnew = ~porta;               // sample active low switches
  swnew &= 0b11110001;          // on RA7..RA4, and RA0 pins
  swnew ^= swold;               // changes, hi or lo
  swold ^= swnew;               // update switch state latch
  swnew &= swold;               // filter out "new lo" bits
  flags |= swnew;               // save "new hi" flag bits
}
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top