first of all thank u,
but my question about c code needed to program pic to do these things,because i don't have any idea how to deal with it.
Regards,
bouz.
Are you talking about the coding of the project or you don't know coding in C?but my question about c code needed to program pic to do these things,because i don't have any idea how to deal with it.
Are you talking about the coding of the project or you don't know coding in C?
Regards,
Jerin.
Do you have the flow chart of the project with you or have you prepared it?
Regards,
Jerin.
Fine..... Did you started writing the code with this flowchart?
Regards,
Jerin. ;-)
Did in which compiler?
Regrads,
Jerin.
MikroC..... Thats nice.... Watz the status till now?
Just post the code & let me see the code. Just provide comments too as much you can along the code.
Regards,
Jerin. ;-)
Actually you should enable the internal pull up resisters on PORT B to get output @ PORT B which would be done by clearing the MSB of the OPTION_REG. So the value for OPTION_REG will be 0x04.OPTION_REG = 0x84; // Prescalar is assigned to timer TMR0
to set the PORT A pins as analog8/digital pins, there is a register called ADCON1 & ADCON0 is used for which channel to select for ADC to work. Also change ANSELH to ADRESH.ANSEL = 0x0C; // Pins AN2 and AN3 are configured as analog
Do one thing buddy. I see that you have written a step:
Actually you should enable the internal pull up resisters on PORT B to get output @ PORT B which would be done by clearing the MSB of the OPTION_REG. So the value for OPTION_REG will be 0x04.
Then,
to set the PORT A pins as analog8/digital pins, there is a register called ADCON1 & ADCON0 is used for which channel to select for ADC to work. Also change ANSELH to ADRESH.
Refer the data sheet for 16F87XA for more details & simulate once again the code & see whether it is working or not.
Regards,
Jerin. ;-)
hi, there is no problem with A/D
i have connect lcd with circuit , but i think there is problem in calculation of heart rate , c the code plz and till me if u found any thing important
/*Header******************************************************/
// LCD module connections
sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D4 at RB0_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D7 at RB3_bit;
sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISB0_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D7_Direction at TRISB3_bit;
// End LCD module connections
unsigned inputsignal=0;
unsigned int firstRun = 1;
unsigned int cnt=0; // Define variable cnt == 1KHz clk
long HR=0;
char *text;
unsigned char outlcd;
void interrupt() {
cnt++; // Interrupt causes cnt to be incremented by 1
TMR0 = 194; // Timer TMR0 is returned its initial value
INTCON = 0x20; // Bit T0IE is set, bit T0IF is cleared
}
void main() {
Lcd_Init(); // LCD display initialization
Lcd_Cmd(_LCD_CURSOR_OFF); // LCD command (cursor off)
Lcd_Cmd(_LCD_CLEAR); // LCD command (clear LCD)
OPTION_REG = 0x84; // Prescaler is assigned to timer TMR0
ANSEL = 0x02; // Pins AN1 is configured as analog
TRISA = 0xFF; // All port A pins are configured as inputs
ANSELH = 0;
TRISC = 0; // All port C pins are configured as outputs
TRISD = 0; // All port D pins are configured as outputs
PORTC = 0x0; // Reset port C
PORTD = 0x0; // Reset port D
ADCON1.F4 = 0 ; // VSS voltage reference
ADCON1.F7 = 1 ; //A/D Conversion Result Format Select bit adfm=1
ADCON0 = 0x07; // A/D is enabled and AN1 is analog input
text = "instantaneous"; // Define the first message
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1,2,text); // Write the first message in the first line
text ="heart rate test";
Lcd_Out(2,1,text);
delay_ms(1000);
delay_ms(1000);
delay_ms(1000);
delay_ms(1000);
delay_ms(1000);
Lcd_Cmd(_LCD_CLEAR);
text ="1)connect";
Lcd_Out(1,1,text);
text="electrodes";
Lcd_Out(2,1,text);
delay_ms(1000);
delay_ms(1000);
delay_ms(1000);
Lcd_Cmd(_LCD_CLEAR);
text ="2)relax please";
Lcd_Out(1,1,text);
delay_ms(1000);
delay_ms(1000);
delay_ms(1000);
while (1){
inputsignal = ADC_Read(1); // Result of A/D conversion is copied to inputsignal
portd = ADRESL;
portc = ADRESH;
if (inputsignal>=600) {
delay_ms(500);
if (firstRun==1)
{
firstRun = 0;
cnt = 0; // Variable cnt is assigned a 0
TMR0 = 194; // Timer T0 counts from 194 to 255
INTCON = 0xA0; // Enable interrupt TMR0
}
else {
//find heart rate
Lcd_Cmd(_LCD_CLEAR);
text="Heart rate=";
Lcd_Out(1,1,text);
//number of interrupt is time between two pulses in ms
HR=60000/cnt;
outlcd=HR/100 ; //hundreds digit in HR
Lcd_Chr(1,12,48+outlcd); // Write result in ASCII format
outlcd=(HR/100)%10;//tens digit in HR
Lcd_Chr_CP(48+outlcd);
outlcd=(HR)%10 ;//ones digit in HR
Lcd_Chr_CP(48+outlcd);
Lcd_out(2,5,"puls/min.");
//rest vlaue of counter
//and start next test
cnt = 0 ;
TMR0 = 194; // Timer T0 counts from 194 to 255
INTCON = 0xA0; // Enable interrupt TMR0
}
}
}
}
Always do write:PORTC = 0x0; // Reset port C
PORTD = 0x0; // Reset port D
Don't assign the bits of a register like ADCON1. It is always desirable to give away a value to the register like, ADCON1 = 0x10;ADCON1.F4 = 0 ; // VSS voltage reference
ADCON1.F7 = 1 ; //A/D Conversion Result Format Select bit adfm=1
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?