Forums MikroC Pro for PIC Project Discussions EMG Click Reply To: EMG Click

#2809

ncyierra
Participant

I read the tutorial. I think the problem is with the code.

I still don’t know how to change the PIC18F87K22 code to work for PIC184862.

#include <stdint.h>
#include <stdbool.h>

void InitTimer1(){
// 200 Hz / 5 ms
T1CON = 0x11;
TMR1IF_bit = 0;
TMR1H = 0x63;
TMR1L = 0xC0;
TMR1IE_bit = 1;
INTCON = 0xC0;
}

static bool read_flag = false;
static volatile uint32_t interrupt_ctr = 0;
static volatile uint32_t seconds_counter = 0;
uint32_t adc_reads;
double timer_reads;

void main()
{
uint32_t i = 0;
char timer_read_string[10];
char final_string [20];

TRISA0_bit = 1; // Set A15 and B8 pins as input
TRISB7_bit = 1;

ADC_Init();

UART1_Init(57600);
delay_ms(500);

while(1)
{
// If the button on PORTB7 is pressed, interrupts are activated
// and the measuring begins
if (Button(&PORTB, 7, 10, 1))
{
UART1_Write_Text(“START\r\n”);
delay_ms(500);
InitTimer1();
}

// Every 3.3 ms measure data and send them to mikroPlot
if (read_flag == true)
{
TMR1IE_bit = 0;
adc_reads = ADC_Get_Sample(0);
timer_reads = ((double)interrupt_ctr) * 5.00;
inttostr(adc_reads, final_string);
floattostr(timer_reads, timer_read_string);
strcat(final_string, “,”);
strcat(final_string, timer_read_string);
ltrim(final_string);
UART1_Write_Text(final_string);
UART1_Write_Text(“\r\n”);
read_flag = false;
TMR1IE_bit = 1;
}
}

}
void Interrupt(){
if (TMR1IF_bit){
TMR1IF_bit = 0;
TMR1H = 0x63;
TMR1L = 0xC0;

read_flag = true;

interrupt_ctr++;
if (interrupt_ctr % 200 == 0)
seconds_counter++;
}
}