code3
code3
Below is a complete example of interfacing an LCD, MAX30100 sensor, and HC-05 Bluetooth
module using mikroC. This code includes all necessary initializations, functions, and comments for
clarity.
#include <built_in.h>
// Function Prototypes
void InitI2C();
void InitUART();
void InitMAX30100();
void ReadMAX30100();
void Lcd_Init();
void Lcd_Clear();
void main() {
// Initialize peripherals
InitI2C();
InitUART();
Lcd_Init();
InitMAX30100();
while(1) {
ReadMAX30100();
SendDataToBluetooth(dataBuffer);
// Display on LCD
Lcd_Clear();
Lcd_Out(1, 1, dataBuffer);
}
}
void InitI2C() {
void InitUART() {
void InitMAX30100() {
I2C1_Start();
I2C1_Stop();
void ReadMAX30100() {
I2C1_Repeated_Start();
I2C1_Stop();
sprintf(dataBuffer, "Red: %u, IR: %u", (redData[0] << 8) | redData[1], (irData[0] << 8) | irData[1]);
while (*data) {
UART1_Write(*data++);
void Lcd_Init() {
TRISB = 0; // Set PORTB as output for LCD control
Delay_ms(2);
Delay_us(500);
LCD_EN = 0;
Delay_us(500);
LCD_EN = 0;
Delay_us(500);
LCD_EN = 0;
Delay_us(500);
LCD_EN = 0;
}
void Lcd_Out(unsigned char row, unsigned char col, unsigned char *text) {
if(row == 1)
else if(row == 2)
while(*text) {
Lcd_Char(*text++);
void Lcd_Clear() {
▎Explanation of Components:
• Initialization:
• Reading Data:
• The ReadMAX30100 function reads the Red and IR values from the MAX30100 sensor and formats
them into a string.
• Sending Data:
• The SendDataToBluetooth function sends the formatted string via UART to the HC-05 module.
• LCD Functions:
• Functions like Lcd_Init, Lcd_Cmd, Lcd_Char, Lcd_Out, and Lcd_Clear handle the operations of the LCD
display.
▎Notes:
• Ensure that you have connected the components correctly in your Proteus simulation or hardware
setup.
• Make sure you have the necessary libraries included based on your mikroC version.
Feel free to modify the code according to your specific needs!