Saturday, January 22, 2022

PIC16F877A Interrupt and Multiplexing Display

In previous post I wrote about Port B interrupt on change. Now I show a programming example using this interrupt and multiplexing display.

PIC16F877A Interrupt and Multiplexing Display

 In this example, Two input button increase and decrease the counting value. Two digits multiplexing display shows its counting content. These two buttons use the interrupt on change of Port B. They don't need to connects to external pull up resistors. Internal weak pull up resistors of Port B are in use.

XC8 Programming

  1. /*
  2.  * PIC16F877a Port B Interrupt On Change
  3.  * And Multiplexing Display Example
  4.  */
  5. #include <xc.h>
  6.  
  7. // PIC16F877A Configuration Bit Settings
  8. // CONFIG
  9. #pragma config FOSC = HS
  10. #pragma config WDTE = OFF
  11. #pragma config PWRTE = OFF
  12. #pragma config BOREN = ON
  13. #pragma config LVP = OFF
  14. #pragma config WRT = OFF
  15. #pragma config CP = OFF
  16.  
  17. #define _XTAL_FREQ 20e6
  18.  
  19. unsigned char cnt=0;
  20.  
  21. /*Multiplexing display routine*/
  22. void driveDisplay(void){
  23. char cCathode[10]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F};
  24.  
  25. PORTC=0x00;
  26. PORTD=cCathode[cnt/10];
  27. RC0=1;
  28. __delay_ms(5);
  29.  
  30. PORTC=0x00;
  31. PORTD=cCathode[cnt%10];
  32. RC1=1;
  33. __delay_ms(5);
  34.  
  35. }
  36.  
  37. void main(void){
  38. /*Clear IO port*/
  39. PORTB=0x00;
  40. PORTC=0x00;
  41. PORTD=0x00;
  42. /*RB4...7 input*/
  43. TRISB=0xF0;
  44. /*Port C and Port D output*/
  45. TRISC=0x00;
  46. TRISD=0x00;
  47. /*Turn on Pull Up Resistor*/
  48. nRBPU=0;
  49. /*Turn On External Interrupt*/
  50. RBIE=1;
  51. /*Turn On Global Interrupt*/
  52. GIE=1;
  53. /*Clear Interrupt Flag*/
  54. RBIF=0;
  55. while(1){
  56. driveDisplay();
  57. }
  58. }
  59.  
  60. /*Interrupt Service Routine*/
  61. void interrupt portBChange(void){
  62. /*Check RB Port Change Interrupt Present*/
  63. if(RBIE&&RBIF){
  64. if(RB6^1) {
  65. if(cnt<99) cnt++;
  66. }
  67. if(RB7^1){
  68. if(cnt>0) cnt--;
  69. }
  70. RBIF=0;
  71. }
  72. }

 Schematic Diagram

PIC16F877A Interrupt and Multiplexing Display
Schematic Diagram

Click here to download source file. We can use a serial to parallel shift registers IC to drive this kind of display.

No comments:

Post a Comment

Search This Blog

Labels

25AA010A (1) 8051 (7) 93AA46B (1) ADC (30) Analog Comparator (1) Arduino (15) ARM (6) AT89C52 (7) ATMega32 (56) AVR (57) CCS PICC (28) DAC (1) DHT11 (2) Display (105) Distance Sensor (3) DS18B20 (3) dsPIC (2) dsPIC30F1010 (2) EEPROM (5) Environment Sensor (4) esp8266 (1) I2C (29) Input/Output (67) Interrupt (19) Keil (5) Keypad (10) LCD (47) Master/Slave (1) MAX7221 (1) MCP23017 (5) MCP23S17 (4) Meter (3) MikroC (2) Motor (15) MPLABX (71) Nokia 5110 LCD (3) OLED (2) One-Wire (6) Oscillator (8) PCB (6) PCD8544 (3) PCF8574 (5) PIC (107) PIC12F (2) PIC16F628A (2) PIC16F630 (1) PIC16F716 (3) PIC16F818 (10) PIC16F818/819 (2) PIC16F84A (15) PIC16F876A (1) PIC16F877A (9) PIC16F88 (1) PIC16F887 (60) PIC18 (19) PIC18F1220 (4) PIC18F2550 (3) PIC18F4550 (12) PWM (11) RTC (8) Sensor (10) SH1106 (1) Shift Register (11) Shift Registers (3) SPI (24) STM32 (6) STM32 Blue Pill (6) STM32CubeIDE (6) STM32F103C8T6 (6) SysTick (3) temperature sensor (11) Thermometer (21) Timer/Counter (31) TM1637 (2) UART (7) Ultrasonic (4) Voltmeter (7) WDT (1) XC16 (2) XC8 (94)