code for mikroC
code for mikroC
#include <xc.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void initI2C() {
SSPADD = 0x09;
void initMax30100() {
initI2C();
configMAX30100();
void configMAX30100() {
int pulseData = 0;
I2C1_Start();
if (I2C1_Write(MAX30100_ADDRESS) == 0) {
I2C1_Write(0x01);
I2C1_ReStart();
if (I2C1_Write(MAX30100_ADDRESS | 0x01) == 0) {
pulseData = I2C1_Read(0);
I2C1_Stop();
return pulseData;
I2C1_Stop();
char pulseDataStr[10];
IntToStr(pulseData, pulseDataStr);
UART1_Write_Text(pulseDataStr);
UART1_Write(0x0D);
UART1_Write(0x0A);
}
// Function to display pulse data on LCD
char pulseDataStr[10];
IntToStr(pulseData, pulseDataStr);
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1, 7, pulseDataStr);
void initLCD() {
Lcd_Init();
Lcd_Cmd(_LCD_CURSOR_OFF);
Lcd_Cmd(_LCD_TWO_LINE);
void initUART1() {
TRISC &= ~(1 << HC05_TX_PIN);
UART1_Init(9600);
UART1_Enable();
UART1_DataBits(8);
UART1_StopBits(1);
UART1_Parity(NONE_PARITY);
void main() {
initMax30100();
initLCD();
initUART1();
while (1) {
sendPulseDataToBluetooth(pulseData);
displayPulseDataOnLCD(pulseData);
} else {
Lcd_Cmd(_LCD_CLEAR);
Delay_ms(100);
}