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.

is the number if I/O pins on a 16f628 enough for my project?

Status
Not open for further replies.

ryan_ryan

New Member
Hi everyone..

I am using the 16f628, i need to build a timer which needs to have mins and seconds as i have mentioned to before. i need 4 * 7seg displays, and probably abt 6 switches to set the mins,secs,start/stop,reset,transmit,one button to switch between master and slave when transmitting , and a buzzer of some kind..I dont think the 16f628 has enough i/0 pins to handle it am i right?

Even by multiplexing the 4 7segs in parallel, i need 4 lines for the transitor to switch them from one 7seg to the other every tmr2 interrupt and update them according, and 8 lines for the 7segs(i need to use on of the decimal pt), 6 for the switches and probably 1 for the buzzer..that would take up 19??? so is the 16f628 still gonna do the job because my lecturer says it can be done..but i am confused since this is my first time programming the PIC..

Besides i am polling the switches and not using ints, i plan to use tmr2 int oly for the display on the 7seg...

Is there any schematics that i can refer to?probably some project with a similiar background??
 
Reset - Normally closed momentary switch that you push to break the +V supply line and discharge any filtering capacitor that may be in the circuit.
B0 is start/stop (good use for the only interrupt pin on this chip?)
B1-7 controls your 7 segment displays.
A0-3 controls the transistors to drive them.
A4 to set time (one button only, start incrementing minute slowly, then fast, so that hour rollovers happen quickly. Easily sets both with only one button).
A5 is the ringy dingy buzzer.
A6 is your transmit line.
A7 is the master/slave selector.

There you go, everything accounted for. Unless your instructor honestly requires two separate buttons for setting the time. In that case, you will have to put the inputs in parallel, just like your parallel outputs. A 2x3 switch array would give you the 6 inputs you need from the 5 available pins. Send out a voltage on of the two output lines, and read the input state of the three input lines. This will let you know if any of the top three buttons are pressed. Then turn off that output and make the second output high. Test all the inputs again. That gives you the three bottom states. You'll want diodes on those two output lines to prevent one from shorting the other.
 
hi,

but i have used up two pins for the crystal already and i need 1 each for the mins and 1 for the sec..using the transmitter module,TRX433, i need 2 lines too..therefore it seems impossible to do my timer with the 16f628 isint it??
 
Consider using 9 pins for a Charlieplexed 7-segment LED display which takes advantage of the I/O pins 'low', 'high', and 'input' states... If you don't have the "low current" displays (very expensive), you'll need to use a PNP transistor driver for each common cathode... Simply stuff an 8 character buffer in you main program and have the ISR routine scan the display (I can provide sample ISR code if you like)...

Consider using the N*(N-1) scheme for multiplexing your switches... 3 pins will give you 6 switches... You'll need a 1N4148 or 1N914 diode for each switch...

9 pins -> 7-segment LED Display
3 pins -> 6 multiplexed switches
2 pins -> Crystal
2 pins -> VDD & VSS
1 pin -> Piezo Speaker
1 pin -> Reset

Actually, since you only need a four or six digit display, we could use other portions of that unused display matrix for the switch inputs but the ISR code will become a little more involved...

Good luck with your project... Regards, Mike
 

Attachments

  • charlieplexed_9-pin_8-digit_cc.jpg
    charlieplexed_9-pin_8-digit_cc.jpg
    104.9 KB · Views: 1,347
Ryan, I got your message... I will try to answer some of your other questions as soon as I can... In the mean time..........

There are a couple rules for using the Charlieplexing scheme... First, only one pin at a time will ever output a '0' to drive the common cathode of one of the LED displays... The other 'segment' pins will either be an output '1' to turn on a segment or an 'input' where the pin will neither sink nor source current to a segment...

Here's some sample ISR code that should be placed between your ISR context save and context restore code (don't forget to turn off the TMR2 interrupt flag too)... Your main program should initialize the BITPOS variable to b'00000001', set the BUFPTR variable to point at the 8 byte DIGIT1 buffer, and set RA0 as an output before setting up and turning on TMR2 interrupts...

Code:
 ;
 ; 8-Digit 9-Pin Charlieplexed CC LED ISR Sample Code
 ;   (14-bit core instructions)
 ;
 ; Vars - BITPOS (float bit & digit position) 
 ;        BUFPTR (buffer pointer)
 ;        DIGIT1 (start of 8 byte display data buffer)
 ;               (bit 7=dp, bit 6=G...bit 0=A)
 ;
 ISR_LED  bsf   STATUS,RP0   ;Bank 1 (RP1 is clr)     |B1
          movlw b'11111111'  ;                        |B1
          movwf TRISB        ;turn off display        |B1
          bcf   STATUS,RP0   ;Bank 0 (RP1 is clr)     |B0
          xorwf BITPOS,W     ;inv float/column bits   |B0
          movwf PORTB        ;new output pattern      |B0
 ;
          bcf   PORTA,0      ;turn 'float bit' off    |B0
          movf  BUFPTR,W     ;ptr to current digit    |B0
          movwf FSR          ;setup indirect address  |B0
          movf  INDF,W       ;get digit segment data  |B0
          andwf BITPOS,W     ;AND float/column bit    |B0
          btfss STATUS,Z     ;need the float bit?     |B0
          bsf   PORTA,0      ;yes, 'float' bit on     |B0
          iorwf BITPOS,W     ;pickup the BITPOS bit   |B0
          iorwf INDF,W       ;get digit segment bits  |B0
          xorlw b'11111111'  ;invert all bits         |B0
          bsf   STATUS,RP0   ;Bank 1 (RP1 is clr)     |B1
          movwf TRISB        ;display new digit       |B1
          bcf   STATUS,RP0   ;Bank 0 (RP1 is clr)     |B0
 ;
          incf  BUFPTR,f     ;increment buffer ptr    |B0
          bcf   STATUS,C     ;clear carry bit         |B0
          rlf   BITPOS,f     ;shift our digit bit     |B0
          btfss STATUS,C     ;all 8 digits scanned?   |B0
          goto  ISR_NXT      ;no, branch              |B0
 ;
          rlf   BITPOS,f     ;reset to b'00000001'    |B0
          movlw DIGIT1       ;get buffer address      |B0
          movwf BUFPTR       ;reset the pointer       |B0
 ;
 ISR_NXT

This code turns on one display each ISR cycle so it takes 8 interrupts to 'scan' all 8 LEDS... Your TMR2 interrupt period will determine the scan rate (refresh rate) and scanning 8 LEDs sequentially results in a 1/8th or 12.5% duty cycle for each LED... Anything over 10% is acceptable but you may have to adjust your segment resistor values for brightness...

At this point your main program simply stuffs the 8 byte DIGIT1 buffer with data for each digit... Bits 6 through 0 in each byte represent segments G through A and bit 7 represents the decimal point... Set a given byte to '00000000' for leading zero suppression and set all 8 bytes to '11111111' for a lamp test function...

Good luck with your project... Regards, Mike
 

Attachments

  • charlieplexed_9-pin_8-digit_cc_2n2907.jpg
    charlieplexed_9-pin_8-digit_cc_2n2907.jpg
    123.2 KB · Views: 1,058
ryan_ryan said:
but i have used up two pins for the crystal already and i need 1 each for the mins and 1 for the sec..using the transmitter module,TRX433, i need 2 lines too..therefore it seems impossible to do my timer with the 16f628 isint it??

The 16F628 has in internal RC oscillator. Although it's not as precise as a crystal, this is just for lab, so its good enough. If you were doing this for your own personal project, or for an actual job, then you'd use a chip that has a higher number of pins to accommodate you. The artificial limitation of "must use a 628 in this lab cuz I say so" pretty well demands you use all of the pins as I/O, and rely on the internal oscillator.
 
Hi Ryan,

Since you only require four of the eight displays, I would add switches to the Charlieplexed display scheme using the LED8 cycle by connecting them as shown below... Add a bit of code near the bottom of the sample ISR code (where we detect that we just setup the LED8 cycle and reset our variables for the upcoming LED1 cycle) to read PORTB and save the 'active low' switch values (RB0..RB6) to another variable for use by your main program... ** Caution ** This scheme requires that you maintain a value of 00h in the LED8 position of the 8 byte DIGIT1 buffer... If any of those bits accidentally get set to '1' the ISR routine would set that bit on PORTB as an output '1' during the LED8 ISR cycle and a switch press on that port pin would result in a short to RB7 (low)... Probably safer to modify the ISR code to insure that TRISB doesn't get set to anything other than '01111111' for the LED8 cycle...

With this scheme you would have your four digit 7-segment LED display and seven switches using just 9 pins...

9 pins -- display & switches
2 pins -- crystal oscillator
2 pins -- VDD and VSS
2 pins -- TRX433 module
1 pin -- Piezo speaker
1 pin -- MCLR/Reset
1 pin --

Hey, you've got a pin left over (grin)... So, to answer your original question -- yes, I think you probably have enough pins on the '628 to do your project... The qualifier is that you need to do some rather tricky multiplexing hardware and code...

Good luck... Regards, Mike
 

Attachments

  • charlieplexed_key_scan.jpg
    charlieplexed_key_scan.jpg
    26 KB · Views: 1,085
Thanks mike

Hi everyone and thanks for the advice,

Thanks mike for the charlieplexing advise u offered me, i have read up the MAX6959 led display which uses this multiplexing method and am not too sure still.Nevertheless, thanks for the willingless to share with me on this schme.

Meanwhile,i have read up the application notes AN234, AN590. With AN234, under digit expansion using an octal latch, i could save up up to 4 I/0 if i used this latch. i was wondering whether if there was any example that demostrates how to use the 74F573 to select the correct displays to update each 7 seg every few milliseconds or just abt any simple eg to show how the switching is done.

I was also wondering i cld multiplexed the switches with the 7 seg lines as shown in AN590, in this diagram every switch line were multiplexed with the 7seg control lines.I have never thought abt this b4 If this can be done, i would think i can just squeeze the number of lines required for my project..

What do u guys think??
 

Attachments

  • clip_image002_132.jpg
    clip_image002_132.jpg
    31.3 KB · Views: 1,195
  • clip_image001.jpg
    clip_image001.jpg
    21.1 KB · Views: 1,175
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top