#define MX_PIC
//Defines for microcontroller
#define P16F628A
#define MX_EE
#define MX_EE_TYPE1
#define MX_EE_SIZE 128
#define MX_UART
#define MX_UART_B
#define MX_UART_TX 2
#define MX_UART_RX 1
#define MX_PWM
#define MX_PWM_CNT 1
#define MX_PWM_TRIS1 trisb
#define MX_PWM_1 3
//Functions
#define MX_CLK_SPEED 4000000
#ifdef _BOOSTC
#include <system.h>
#endif
#ifdef HI_TECH_C
#include <pic.h>
#endif
//Configuration data
#ifdef _BOOSTC
#pragma DATA 0x2007, 0x3f38
#endif
#ifdef HI_TECH_C
__CONFIG(0x3f38);
#endif
//Internal functions
#include "C:\Program Files\Matrix Multimedia\Flowcode V4\FCD\internals.h"
//Macro function declarations
void FCM_tint(); // this macro is called when timer0 interrupt occurs
void FCM_tm1(); //this macro is called when INT (pin RB0) interrupt occurs
//Variable declarations
//Defines:
/**** Macro Substitutions ****
porta = LED Port Register
trisa = LED Data Direction Register
1 = LED Pin Mask
1 = LED Active Polarity
******************************/
//LED(0): //Macro function declarations
void FCD_LED0_LEDOn();
void FCD_LED0_LEDOff();
//LED(0): //Macro implementations
void FCD_LED0_LEDOn()
{
#ifdef MX_10F_TRIS
tvar = tvar & ~1;
asm("movf(_tvar),w");
asm("tris 6");
#else
trisa = trisa & ~1; //Convert pin to output
#endif
if( 1 ) //Active high polarity
porta = porta | 1;
else //Active low polarity
porta = porta & ~1;
}
void FCD_LED0_LEDOff()
{
#ifdef MX_10F_TRIS
tvar = tvar & ~1;
asm("movf(_tvar),w");
asm("tris 6");
#else
trisa = trisa & ~1; //Convert pin to output
#endif
if( 1 ) //Active high polarity
porta = porta & ~1;
else //Active low polarity
porta = porta | 1;
}
//Macro implementations
void FCM_tint()
{
//C Code
//C Code:
tmr0 = 128;
//Call Component Macro
//Call Component Macro: LED(0)::LEDOn
FCD_LED0_LEDOn();
//Delay
//Delay: 1 us
delay_us(1);
//Call Component Macro
//Call Component Macro: LED(0)::LEDOff
FCD_LED0_LEDOff();
}
void FCM_tm1()
{
//Interrupt (timer0)
//Interrupt: Enable TMR0
cr_bit(option_reg,T0CS);
st_bit(option_reg,T0SE);
option_reg = (option_reg & 0xF0) | 0x07;
st_bit(intcon,GIE);
st_bit(intcon, T0IE);
}
void main()
{
//Initialisation
cmcon = 0x07;
//Interrupt initialisation code
option_reg = 0xC0;
//Interrupt (INT)
//Interrupt: Enable RB0INT
st_bit(option_reg,INTEDG);
st_bit(intcon,GIE);
st_bit(intcon, INTE);
//Loop
//Loop: While 1
while (1)
{
}
mainendloop: goto mainendloop;
}
void MX_INTERRUPT_MACRO(void)
{
//Handler code for [RB0INT]
#ifndef MX_INTHANDLER_intcon_INTF
#define MX_INTHANDLER_intcon_INTF
if (ts_bit(intcon, INTF) && ts_bit(intcon, INTE))
{
FCM_tm1();
cr_bit(intcon, INTF);
}
//Handler code for [TMR0]
#ifndef MX_INTHANDLER_intcon_T0IF
#define MX_INTHANDLER_intcon_T0IF
if (ts_bit(intcon, T0IF) && ts_bit(intcon, T0IE))
{
FCM_tint();
cr_bit(intcon, T0IF);
}
}
I did not find any tutorial regarding PEIE bit of INTCON register.
...
Could you please clarify this thing?
#define _XTAL_FREQ 4000000
#include <htc.h>
char iniDelay,count;
void interrupt isr(void)
{
if(INTCON & (1<<1)) //check Ext Int Flag (INTF)
{
PORTA &=~1; //clear RA0
INTCON |=(1<<5); //set TMR0 Overflow Int Enable bit (T0IE)
TMR0=256-iniDelay;
INTCON &=~ (1<<1); //clear Ext Int Flag (INTF)
}
if(INTCON & (1<<2)) //check TMR0 overflow Int Flag (T0IF)
{
INTCON|=(1<<4); //set Ext Int Enable bit (INTE)
INTCON &=~ (1<<2); //clear TMR0 Overflow Interrupt Flag bit (T0IF)
INTCON &=~ (1<<5); //clear TMR0 Overflow Int Enable bit (T0IE)
PORTA |= 1; //set RA0
}
}
void main()
{
char pB,p,pB2,pOut;
CMCON = 0b00000111; //comperators are off
OPTION_REG=(1<<6); //set Interrupt Edge Select bit, INTEDG (rising) //clear bit#7: enable PORTB pull-up resistors
OPTION_REG|=(1<<3);
OPTION_REG|=0b00000111; //Prescaler Rate for TMR0, 1:256
INTCON |=((1<<7) | (1<<4)); //set GIE and INTE
TRISA = 0x00; //PortA as Output
TRISB = 0xFF; //PortB as input
PORTA=0xff;
iniDelay=20;
//PORTA &=~(1<<1); //clear
start:
PORTA &=~1;
pB=PORTB;
while (pB>1 && pB<8)
{
scan:
pB2=PORTB;
if (pB2<=1)
{
if (pB>=2 && pB<4)
{
if (iniDelay<36){
iniDelay=iniDelay+2;
}
}
if (pB>=4 && pB<8)
{
if (iniDelay>4){
iniDelay=iniDelay-2;
}
}
pB=0;
}
else goto scan;
} //end while loop
goto start;
}
I wrote the following code (Hi Tech C) using INT and Timer0 and it is working in MPLAM as expected. But it is not working in Proteus.
How do you know it is working in MPLAB, did you run it in SIM?
Check in htc.h file, looks like the defined memory location is not available in H/W
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?