0
#include "_ffmc16.h"
#include "extern.h"
#include "monitor.h"

void initLCD();
void delay();
void instCtrl4(unsigned char data);
void display(unsigned char temp);
void display1(unsigned char pulse, int counter);
void decoder(int newtemp);
void instCtrl(unsigned char data);
void dataCtrl(char data);

#define RS IO_PDR2.bit.P24
#define RW IO_PDR5.bit.P53
#define E IO_PDR5.bit.P52
#define LCD IO_PDR2.byte
#define BUZZER IO_PPGC23.bit.PEN1

unsigned char AD_DATA, temperature, bpm;
int count = 0, counter=0;
int UpperThreshold = 518;
int LowerThreshold = 490;
int IgnoreReading = 0;
int FirstPulseDetected = 0;
    unsigned char FirstPulseTime = 0;
    unsigned char SecondPulseTime = 0;
    unsigned char PulseInterval = 0;
    unsigned char BPMResult;


void main()
{
    __set_il(7);
    __EI(); 

    IO_DDR2.byte = 0x1F; 
    IO_DDR5.bit.D53 = 1; 
    IO_DDR5.bit.D52 = 1; 

    IO_ADER.bit.ADE3 = 0; 
    IO_ADER.bit.ADE2 = 0; 





    //BUZZER
    IO_PPGC23.bit.PE1=0x01;
    IO_PPG23.byte=0x00;
    IO_PRL23.byte.PRLL3=0xFA;
    IO_PRL23.byte.PRLH3=0xFA;


    initLCD();
    instCtrl(0x84);
    dataCtrl('T');
    dataCtrl('E');
    dataCtrl('M');
    dataCtrl('P');
    dataCtrl('E');
    dataCtrl('R');
    dataCtrl('A');
    dataCtrl('T');
    dataCtrl('U');
    dataCtrl('R');
    dataCtrl('E');
    dataCtrl(':');

    instCtrl(0x99);
    dataCtrl('P');
    dataCtrl('U');
    dataCtrl('L');
    dataCtrl('S');
    dataCtrl('E');
    dataCtrl('R');
    dataCtrl('A');
    dataCtrl('T');
    dataCtrl('E');
    dataCtrl(':');

    while(1)
    {
    counter++;

    IO_DDR5.bit.D55 = 0;    /* PORT5 DDR set(AD1) */
    IO_ICR03.byte = 0x00;   /* A/D INT level set */
    IO_ADCSH.bit.BUSY = 0;  /* ADC stop */
    IO_ADER.byte = 0x02;    /* ADC input enable, ch-1 */
    IO_ADCSL.byte = 0xAD;   /* ADC mode set */
    IO_ADCRLH.byte.ADCRH = 0xF8;    /* set 8bit-AD, comp.176cycle, sample.128cycle */
    IO_ADCSH.bit.INTE = 1;  /* interrupt enable */
    IO_ADCSH.bit.STRT = 1;  /* start ADC */

        display(AD_DATA);

        /*if(temperature>38)
        {
            BUZZER=0x01;
        }
        else if(temperature<34)
        {
            BUZZER=0x01;
        }
        else
        {
            BUZZER=0x00;
        }*/


    IO_DDR5.bit.D54 = 0;    /* PORT5 DDR set(AD1) */
    IO_ICR03.byte = 0x06;   /* A/D INT level set */
    IO_ADCSH.bit.BUSY = 0;  /* ADC stop */
    IO_ADER.byte = 0x10;    /* ADC input enable, ch-1 */
    IO_ADCSL.byte = 0xA4;   /* ADC mode set */
    IO_ADCRLH.byte.ADCRH = 0xF8;    /* set 8bit-AD, comp.176cycle, sample.128cycle */
    IO_ADCSH.bit.INTE = 1;  /* interrupt enable */
    IO_ADCSH.bit.STRT = 1;  /* start ADC */ 
        display1(AD_DATA, counter);
    }
}

void delay()
{
    for(count=0; count<1000;count++)
    {
    }
}

void initLCD()
{
    delay();
    instCtrl4(0x03);
    delay();
    instCtrl4(0x03);
    delay();
    instCtrl4(0x03);
    delay();
    instCtrl4(0x02);
    delay();
    instCtrl(0x28);
    instCtrl(0x08); //off
    instCtrl(0x01); //clear
    instCtrl(0x06); //entry mode: increment or shift mode
    instCtrl(0x0C); //display on; cursor on;blink on
    instCtrl(0x01);
}

void instCtrl4(unsigned char data)
{
    LCD = data;
    RS = 0;
    RW = 0;
    E =1;
    delay();
    E =0;
}

void display(unsigned char temp)
{
    temperature = (temp * 500) / 255;
    instCtrl(0xC8);
    decoder((temperature/10)%10); 
    decoder(temperature%10); 
    dataCtrl(0xDF);
    dataCtrl('C');
}

void display1(unsigned char pulse, int counter)
{


    /*if(pulse > UpperThreshold && IgnoreReading == 0)
    {
        if(FirstPulseDetected == 0)
        {
          FirstPulseTime = counter;
          FirstPulseDetected = 1;
        }
        else
        {
          SecondPulseTime = counter;
          PulseInterval = SecondPulseTime - FirstPulseTime;
          FirstPulseTime = SecondPulseTime;
        }
        IgnoreReading = 1;
      }

      // Heart beat trailing edge detected.
      if(pulse < LowerThreshold)
      {
        IgnoreReading = 0;
      }  

      BPMResult = (1 / PulseInterval) * (60000);*/

      //bpm= pulse; /* default n ??*/




    instCtrl(0xD9);
    decoder((BPMResult/100)%10);
    decoder((BPMResult/10)%10); 
    decoder(BPMResult%10); 
    dataCtrl('B');
    dataCtrl('P');
    dataCtrl('M');
}

void decoder(int newtemp)
{
    switch(newtemp)
    {
        case 0:
            dataCtrl('0');
            break;
        case 1:
            dataCtrl('1');
            break;
        case 2:
            dataCtrl('2');
            break;
        case 3:
            dataCtrl('3');
            break;
        case 4:
            dataCtrl('4');
            break;
        case 5:
            dataCtrl('5');
            break;                                                                                                                                      
        case 6:
            dataCtrl('6');
            break;
        case 7:
            dataCtrl('7');
            break;
        case 8:
            dataCtrl('8');
            break;
        case 9:
            dataCtrl('9');
            break;
    }
}

void instCtrl(unsigned char data)
{
    LCD=data>>4;
    RS =0;
    RW=0;
    E=1;
    delay();
    E=0;
    LCD=data;
    RS=0;
    E=1;
    delay();
    E=0;
}

void dataCtrl(char data)
{
    LCD=data>>4;
    RS=1;
    RW=0;
    E=1;
    delay();
    E=0;
    LCD=data;
    RS=1;
    E=1;
    delay();
    E=0;
}

__interrupt void ADC_int(void)
{   
    IO_ADCSH.bit.INT = 0;       //interrupt flag clear
    AD_DATA = IO_ADCRLH.DATA8;  //A/D conversion interrupt vector
}

/* Vector Table */
#pragma section INTVECT, locate=0xfffc00
#pragma intvect _start      0x8     0x0 /* Reset Vector */
#pragma intvect ADC_int     18      /* AD converter vector */
  • what is your question? – jsotola Jan 9 at 8:08
  • Agreed, if you don't actually ask anything, then what replies do you expect to receive? – MichaelT Jan 9 at 8:17
  • Can you check my code.. because my Pulse Sensor Formula is only displaying 96BPM – Joshua Pales Jan 10 at 3:31
  • @jsotola Do you have a formula for pulse sensor? – Joshua Pales Jan 10 at 3:53
  • what pulse sensor? .... a quick google search reveals that the MB90F387 is a fujitsu microcontroller and FMC-16LX is a cable that is used to program the MB90F387 ..... the whole thing is not even related to an Arduino .... either way, as far as i can tell, you have provided no information about the sensor – jsotola Jan 10 at 5:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.