pia-468x60

pia-728x90

Showing posts with label PIC16 Microcontrollers. Show all posts
Showing posts with label PIC16 Microcontrollers. Show all posts

Saturday, May 28, 2022

A DIY Calculator Using PIC16F876A

I decide to make a simple digital calculator with my own components, seven-segment display. PIC16F876A, and push button, etc. However it's not useful in current application because a calculator presents in many electronics device such as a smart phone, tablet, and personal computer, etc.

A DIY Calculator Using PIC16F876A
A DIY Calculator Using PIC16F876A 

This calculator is able to handle up to 8 digits, including a negative sign. It can perform arithmetic addition, subtraction, multiplication, and division. The data type is only signed integer number. 

I use MikroC Pro for PIC to program this typical 8-bit controller. The total lines of code is quite high.

  1.  
  2.  
  3. #define GA (1<<3)
  4. char keypadPort at PORTB;
  5. char key_char[16]= {7,8,9,15,4,5,6,14,1,2,3,13,10,0,11,12};
  6. char send_key,dig[8];
  7. unsigned char cnt;
  8.  
  9. void interrupt(void){
  10. if(INTCON.TMR0IF)
  11. cnt++;
  12. INTCON.TMR0IF=0;
  13. }
  14.  
  15. void system_init();
  16. void ssd_out();
  17.  
  18. void main() {
  19. char key=0,old_key=0;
  20. char i=0,j=0;
  21. char CntKey=0;
  22. system_init();
  23. while(1){
  24. key=Keypad_Key_Click();
  25. if(key!=0&&CntKey<8){
  26. send_key=key-1;
  27. /*dig[5]=dig[4];
  28.   dig[4]=dig[3];
  29.   dig[3]=dig[2];
  30.   dig[2]=dig[1];
  31.   dig[1]=dig[0];*/
  32. for(i=7;i>0;i--) dig[i]=dig[i-1];
  33. dig[0]=key_char[send_key];
  34. CntKey++;
  35. }
  36.  
  37. ssd_out();
  38. }
  39. }
  40.  
  41. void system_init(){
  42. TRISC=0x00;
  43. TRISA=0x00;
  44. PORTA=0x00;
  45. PORTC=0x00;
  46. ADCON1=0x07;
  47. OPTION_REG=0x85;
  48. INTCON.GIE=1;
  49. INTCON.TMR0IE=1;
  50. INTCON.TMR0IF=0;
  51. Keypad_Init();
  52. cnt=0;
  53. send_key=0;
  54. }
  55.  
  56. void ssd_out(){
  57. const char sg[16]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,
  58. 0x07,0x7F,0x6F,0x77,0x7C,0x39,0x5E,0x79,0x71} ;
  59. // const char dg[6]={0x20,0x10,0x08,0x04,0x02,0x01};
  60. switch(cnt){
  61. case 1:
  62. PORTA=0x00;
  63. PORTC=sg[dig[7]];
  64. PORTA=0x00|GA;
  65. break;
  66.  
  67. case 2:
  68. PORTA=0x00;
  69. PORTC=sg[dig[6]];
  70. PORTA=0x01|GA;
  71. break;
  72.  
  73. case 3:
  74. PORTA=0x00;
  75. PORTC=sg[dig[5]];
  76. PORTA=0x02|GA;
  77. break;
  78.  
  79. case 4:
  80. PORTA=0x00;
  81. PORTC=sg[dig[4]];
  82. PORTA=0x03|GA;
  83. break;
  84.  
  85. case 5:
  86. PORTA=0x00;
  87. PORTC=sg[dig[3]];
  88. PORTA=0x04|GA;
  89. break;
  90.  
  91. case 6:
  92. PORTA=0x00;
  93. PORTC=sg[dig[2]];
  94. PORTA=0x05|GA;
  95. break;
  96.  
  97. case 7:
  98. PORTA=0x00;
  99. PORTC=sg[dig[1]];
  100. PORTA=0x06|GA;
  101. break;
  102.  
  103. case 8:
  104. PORTA=0x00;
  105. PORTC=sg[dig[0]];
  106. PORTA=0x07|GA;
  107. break;
  108.  
  109. case 9:
  110. cnt=1;
  111. PORTA=0x00;
  112. break;
  113. }
  114.  
  115. }

I use keypad library of this compiler to scan its 4x4 matrix keypad.

A DIY Calculator Using PIC16F876A
Schematic Diagram

The PCB is assumed to be a single side layer. It's easy to fabricate at home.

A DIY Calculator Using PIC16F876A
Bottom Layer copper normal no mirror

A DIY Calculator Using PIC16F876A
Top silk normal no mirror
A DIY Calculator Using PIC16F876A
A sample 3D design

A DIY Calculator Using PIC16F876A
Top side

A DIY Calculator Using PIC16F876A
Bottom side

Click here to download its source file.



Thursday, March 31, 2022

A DIY Timer/Scheduler and temperature controller using PIC16F876A

Introduction

A timer is useful in any task that requires a specific time or a duration that the target device will turn on and off. It is easily found at low price. For electronic hobbyists, a timer can easily be created using a typical timer IC NE555 with other dozen of components.

Here I design a timer using a small microcontroller - PIC16F876A. It's suitable to handle timing setting, displaying, controlling, and scheduling. 

A DIY Timer/Scheduler and temperature controller using PIC16F876A
Main menu of this timer

This timer can handle the following tasks:

  1. Main menu - displaying date/time, and temperature
  2. Date/Time setting
  3. Short 16 hours timer
  4. Temperature setting for an output relay
  5. Scheduling daily on time of timer relay

A DIY Timer/Scheduler and temperature controller using PIC16F876A
Day of Week Adjust

A DIY Timer/Scheduler and temperature controller using PIC16F876A
Time Adjust

A DIY Timer/Scheduler and temperature controller using PIC16F876A
Date Adjust

A DIY Timer/Scheduler and temperature controller using PIC16F876A
Short timer up to 16 hours



A DIY Timer/Scheduler and temperature controller using PIC16F876A
Temperature Adjusting for output relay

A DIY Timer/Scheduler and temperature controller using PIC16F876A
Daily On Time Adjusting

Design

Firmware

I use MicroC Pro PIC to program this device. The operation of this device become abnormal whenever I try to add more function in C source code. So I tried to optimize, reduce, and test this project as much as I can to make the operation more stable.

Listing below is the source code for v1.2 of this project.

  1.  
  2. #include "board.h"
  3.  
  4. void main() {
  5. LCD_Set();
  6. DS1307_Init();
  7. T_Init();
  8. TMR0_SETUP();
  9. SCH_READ();
  10. while(1){
  11. Menu_Scan();
  12. Selector();
  13. SCH_RUN();
  14. }
  15. }

We can only see a dozen lines of code, as they are separated in different files. Click here to download firmware and design file.

Hardware

I designed this project using Proteus 8. This program also allow us to simulate.

A DIY Timer/Scheduler and temperature controller using PIC16F876A
Schematic

Circuit board is very simple. It can be made using toner transfer method.

A DIY Timer/Scheduler and temperature controller using PIC16F876A
PCB design view
A DIY Timer/Scheduler and temperature controller using PIC16F876A
Copper track

A DIY Timer/Scheduler and temperature controller using PIC16F876A
Top silk


A DIY Timer/Scheduler and temperature controller using PIC16F876A
Design view in 3D

A DIY Timer/Scheduler and temperature controller using PIC16F876A
Idle

A DIY Timer/Scheduler and temperature controller using PIC16F876A
Top Side

A DIY Timer/Scheduler and temperature controller using PIC16F876A
Bottom Side



Labels

ADC (11) Analog (15) Arduino (12) Atmega16 (19) Audio (2) AVR (20) CCS PICC (3) Charger (1) Cortex-M0 (1) Counter (10) CPLD (25) DHT11 (1) Digital I/O (23) Display (37) ds18B20 (1) EEPROM (2) Environment Sensor (2) esp8266 (2) Experiment Board (12) I2C (4) Interrupt (8) LCD (3) LDmicro (29) measurement and instrumentation (7) Microchip Studio (3) MikroC (1) One-Shot (3) OpAmp (1) PCB (32) PIC16 Microcontrollers (16) PIC16F877A (2) PIC16F887 MikroC (22) pic18 microcontrollers (2) PIC18F4550 (3) PLC (35) PWM (11) Regulator (1) RTC (3) Sensor (9) Shift Registers (5) SPI (5) Timer (34) UART (2) ultra-sonic sensor (1) USB (2) VHDL (21) xc8 (1) XC95108 (9) XC9536 (15) XC9572 (1) Xilinx (23) Xilinx ISE (22)