PROTEUS FOR MPLAB X IDE CODE
Implementation of the code on real Hardware.
PROTEUS FOR MPLAB X IDE PROFESSIONAL
#include "LCD_Lib.Development of an automatic hand gel dispenser using the PIC18F46K22 microprocessor with MPLAB X IDE v5.25 as a compiler and Proteus 8 Professional for the simulation. #define LED_PIN RB4 // Alarm LED is connected to RB4 pin #define button3 RB3 // button B2 is connected to RB3 pin #define button2 RB2 // button B2 is connected to RB2 pin #define button1 RB1 // button B1 is connected to RB1 pin
PROTEUS FOR MPLAB X IDE SOFTWARE
* This is a free software with NO WARRANTY. * Time and date are displayed on 1602 LCD screen. * using PIC16F887 microcontroller and DS3231 (DS3232). * Real time clock with 2 alarm functions and temperature monitor
The microcontroller used in this example is PIC16F887, configuration words are: I2C_Write(4 | ((!(status_reg & 1)) & alarm1_status) | (((!((status_reg > 1) & 1)) & alarm2_status) alarm 1 is ON and if alarm1_status is 0 => alarm 1 is OFF.
I used the following line to write 1 to the INTCN bit and to turn OFF the occurred alarm: Turning ON or OFF an alarm is done by writing to the control register (bits: INTCN, A1IE and A2IE). To do that we’ve to detect which alarm has been occurred which can be easily done by reading the status register of the DS3231 (A1IF and A2IF flag bits). If both alarms are active, button B2 will reset and turn OFF the occurred alarm only and keep the other as it is. Button B2 resets and turns OFF the alarm. The microcontroller turns the LED ON (connected to pin RB4) when it is interrupted by the DS3231, the DS3231 sends the interrupt signal (pulls down the INT line) when there has been an alarm (alarm 1 or alarm 2). To be able to compile the C code, a small LCD library for MPLAB XC8 compiler is required which can be downloaded from the following link:Īfter the download, add the library file ( LCD_Lib.c) to project folder. The C code below is for MPLAB XC8 compiler, it was tested with version 2.00 installed on MPLAB X IDE version 5.05. Real time clock with alarm and temperature monitor C code: In this project the PIC16F887 microcontroller runs with its internal oscillator 8 MHz, MCLR pin is configured as an input pin. A (anode) and K (cathode) are the back light LED pins. VEE pin is used to control the contrast of the LCD. VDD to +5V and A to +5V through 330 ohm resistor VEE to the variable resistor (or potentiometer) output pin VSS, RW, D0, D1, D2, D3 and K are connected to circuit GND (ground) The 20×4 LCD screen is connected to the PIC16F887 microcontroller as follows: Buttons B3 and B2 adjust alarm 1 and alarm 2 parameters (hours, minutes and ON/OFF), button B3 selects the parameter and B2 increments the selected parameter.Īlso, there is an LED connected to PIC16F887 pin RB4 (#37), this LED is used as an alarm indicator (alarm 1 and alarm 2), so if there is an alarm, the DS3231 pulls down the INT pin (RB0) which interrupts the microcontroller and the microcontroller turns the LED ON, here button B2 turns both the LED and the occurred alarm OFF. Time and date can be adjusted with B1 and B2, button B1 selects time or date parameter (time parameters: hours and minutes date parameters: day of the week, date, month and year) and B2 increments the selected parameter. These buttons are used to set time, date and alarms. In the circuit there are 3 push buttons: B1, B2 and B3. The DS3231 interrupts the microcontroller when there is an alarm (alarm 1 or alarm 2). The DS3231 board is supplied with 5V as the 2004 LCD and the PIC16F887 microcontroller, there are 3 data lines connected between this board and the microcontroller: SCL line is connected to pin RC3 (#18), SDA line is connected to pin RC4 (#23) and INT line is connected to external interrupt pin RB0 (#33). (All grounded terminals are connected together)