Microcontroller › PIC › Count no. of pulses using interrupts
- This topic has 0 replies, 1 voice, and was last updated 9 years, 10 months ago by Jayant Gupta.
-
AuthorPosts
-
January 27, 2015 at 1:51 pm #3417Jayant GuptaParticipant
i am using pic18f1330 and the tools used for this program are mplab and high tech c 18
i am developing a code in which i need to count the number of pulses fed to the interrupt pin A1.
as soon as the rising edge is detected at this interrupt pin the value of the count on lcd should be incremented by 1 between the places 0x8f and 0x86 on lcd and no edge is detected it should stop incrementing.
please provide me help in what am i doing wrong in this program
this is the code
#include<htc.h>
#include”define.h”
#include”delay.h”
#include”lcd.h”/*Configuration bits for the micro controller*/
__CONFIG(1, RCIO & IESODIS & FCMDIS); // INTERNAL OSC. & INTERNAL/EXTERNAL OSC. & FAIL SAFE CLOCK MONITOR
__CONFIG(2, BORDIS & PWRTDIS & WDTDIS); // Disable WATCHDOG TIMER & POWER UP ENABLE BIT & BROWN OUT RESET ENABLE
__CONFIG(3, MCLRDIS); // MASTER CLEAR & MCU is in USER MODE : DEFAULT
__CONFIG(4, DEBUGDIS & STVRDIS )
; // STACK OVERFLOW/UNDER FLOW RESET Disabled
__CONFIG(5, UNPROTECT); // write protectionunsigned char screen;
volatile int count=0;
int i=0;void pic_init(void)
{
PORTA=0x00;
TRISA=0x00; // port a is output
PORTB=0x00;
TRISB=0x00; // port b is output/*Oscillator Configuration*/
OSCCON=0xFF; // oscillator configuration for 8MHz and stabalize the freq./*making the analog pins as digital fordigital purpose*/
ADCON1=0xFF; // analog pins are digital/*analog pin configuration for 4-20 mA and button interfacing*/
TRISA0=1; // input for buttons
TRISA1=1; // input for pulser feed
TRISA2=1;
TRISA3=1;/*for mode selection*/
TRISA5=1; // MCLR pin for admin and user mode/* Interrupt Registers Configuration*/
/* interrupt control register configuration bit wise
7-all global interrupts disabled
6-all peripheral interrupts disabled
5-disabled TMR0 overflow interrupt
4-INT0 external interrupt disabled
3-RB port change interrupt disabled
2-TMR0 register overflow not occured
1-INT0 external interrupt did not occur
0-RB7:RB4 pins have not changed states*/
INTCON = 0x00;
/*7-portB pull ups are enabled by individual port latch values
6-external interrupt 0 on falling edge
5-external interrupt 1 on falling edge
4-external interrupt 2 on falling edge
3-external interrupt 3 on falling edge
2-TMR0 overflow interrupt priority is low
1-INT3 external interrupt priority is low
0-RB port change interupt priority is low*/
INTCON2 = 0x00;
/*7-INT2 external interrupt priority is low
6-INT1 external interrupt priority is low
5-disable INT3 external interrupt
4-disable INT2 external interrupt
3-disable INT1 external interrupt
2-INT3 external interrupt did not occur
1-INT2 external interrupt did not occur
0-INT1 external interrupt did not occur*/
INTCON3 = 0x00;/*PWM power control configuration*/
PWMEN2 = 0; // PWM CONTROL REGISTER
PWMEN1 = 0; // PWM Module are DISABLED
PWMEN0 = 0; // All PWM I/O are GPIO/*configuration for low voltage control register to save data in case of power failure*/
LVDEN = 0; // Disable module
LVDL3 = 1; // VOLTAGE DETECTION
LVDL2 = 1; // LIMIT BITS
LVDL1 = 1; // MAXIMUM
LVDL0 = 0; // SETTING
LVDEN = 1; // Enable LVD module
LVDIF = 0; // LOW VOLTAGE DETECT INTERRUPT FLAG
LVDIE = 1; // LOW VOLTAGE DETECT INTERRUPT ENABLE
LVDIP = 1; // LOW VOLTAGE DETECT INTERRUPT PRIORITY/* Timer1 configuration register bits*/
}
void main()
{
pic_init();
DelayMs(1);
lcd_init();
CLEAR_SCREEN
lcd_cmd(0x83);
welcome
DelayMs(250);DelayMs(250);/*test for the detection of the RA5 pin to configure between admin and user mode*/
// if(RA5==1){TOP_LINE lcd_array(“ADMIN MODE”);}
// else{TOP_LINE lcd_array(“USER MODE”);}/*the LPTT screen setting*/
screen=normal;
CLEAR_SCREEN
/*External Interrupt configuration*/
GIE=1; // enable global interrupts
PEIE=1; // peripheral interrupt enable bit
INT1IE=1; // INT1 external interrupt is enabled
INT1IF=0; // INT1 external interrupt enabled
PCFG1=1; // make RA1 pin as digital
INTEDG1=1; // interrupt on rising edge
while(1)
{}
}void counter()
{
unsigned int temp1=9,temp2;
for(int j=0;j<=999999999;j++)
{
for(unsigned char x=0x8F;x>=0x86;x–)
{
temp1=temp1/10;
temp2=temp1%10;
lcd_data((temp2)+48);temp1++;
lcd_cmd(x);
}
}
}void interrupt isr(void)
{
int i=0;
if(INT1IF==1)
{
GIE=0; // disable global interrupts
INT1IF=0; // disable interrupt flag
counter();
INT1IF=1;
GIE=1;
}
}thank you very much
-
AuthorPosts
- You must be logged in to reply to this topic.