Sunday, January 14, 2024

PIC16F887 TM1637 Display and Key Scan Example using XC8

In previous post, we use TM1637 to display 7-Segment data. This chip has a 8x2 key scan circuit, giving a 16 different key value. This advantage is suitable for most of household electronics appliances, washing machine, induction cooker, micro-wave oven, etc.

PIC16F887 TM1637 Display and Key Scan Example using XC8
Simulating Program
 

To read key, the micro-processor must send the read key scan data command (0x42), follows by one more start command, and the process the serial data input receiving. Least Significant Bit (LSB) is received first. However received key scan data is in reverse direction. So the we need to re-arrange it, or process the receiving data using MSB first. For example, the key value of "1110_1111" is equal to 0xF7 (1111_0111).

PIC16F887 TM1637 Display and Key Scan Example using XC8
Key Scan Diagram








PIC16F887 TM1637 Display and Key Scan Example using XC8
Address Command Setting

In this example, the program keeps scanning and receiving key scan data. It will show on the 7-Segmen display one by one, right to left.

  1. /*
  2.  * File: main.c
  3.  * Author: Admin
  4.  *
  5.  * Created on January 14, 2024, 5:51 PM
  6.  */
  7.  
  8. #include <xc.h>
  9. #include "config.h"
  10. #include "tm1637.h"
  11.  
  12. #define _XTAL_FREQ 8000000UL
  13.  
  14. void main(void) {
  15. char data=0;
  16. char txt[7];
  17. OSCCONbits.IRCF=7;
  18. TM1637Init();
  19. PORTC=0;
  20. TRISC=0;
  21. display(1,data_7[1]);
  22. display(2,data_7[6]);
  23. display(3,data_7[3]);
  24. display(4,data_7[7]);
  25. __delay_ms(2500);
  26. clearDisplay();
  27. while(1){
  28. data=scanKey();
  29. if(data!=0xFF) {
  30. PORTC=data;
  31. txt[6]=data_7[findKey(data)];
  32. for(uint8_t i=0;i<6;i++) txt[i]=txt[i+1];
  33. for(uint8_t i=0;i<6;i++) display(i,txt[i]);
  34. __delay_ms(250);
  35. }
  36. }
  37. return;
  38. }
  39.  

The clock frequency must not exceed 250kHz. I wrote my own driver with some idea from other GitHub users. Most of libraries for this chip are design to run on Arduino.


 

Click here to download its source file.

 

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 (54) 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 (46) Master/Slave (1) MAX7221 (1) MCP23017 (5) MCP23S17 (4) Meter (3) MikroC (2) Motor (15) MPLABX (66) 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 (2) SPI (24) STM32 (6) STM32 Blue Pill (6) STM32CubeIDE (6) STM32F103C8T6 (6) SysTick (3) temperature sensor (11) Thermometer (21) Timer/Counter (30) TM1637 (2) UART (7) Ultrasonic (4) Voltmeter (7) WDT (1) XC16 (2) XC8 (94)