Archives
-
Interrupt handling using pic16f877a
Hi Tahmid,
I am using mickoC and proteus for simulation.
Please tell me some advices regarding the problem of this code.
This code is for our traffic light project and I’ve got a problem with the push button(which is the interrupt), it won’t work.Code:
int j=5;
int i=0;
int count = 0;void interrupt(void)
{
for(i=0;i<5;i++)
{
PORTA = 0xFF;
PORTC = 0×00;
PORTD = 0×00;
Delay_ms(1000);
PORTC = 0x0F;
PORTD = 0xF0;
Delay_ms(1000);
count = count + 1;
}
PORTA = 0×00;
PORTC = 0xF0;
PORTD = 0x0F;Delay_ms(5000);
for(j=5;j<10;j++)
{
PORTA = 0xFF;
PORTC = 0×00;
PORTD = 0×00;
Delay_ms(1000);
PORTC = 0xF0;
PORTD = 0x0F;
Delay_ms(1000);
count = count + 1;
}PORTA = 0×00;
PORTC = 0x0F;
PORTD = 0xF0;
INTCON.INTF = 0; //You HAVE to clear interrupt flag
}void main() {
INTCON.GIE = 1; //Enable Global Interrupt
INTCON.INTE = 1; //Enable RB0/INT external Interrupt
INTCON.PEIE = 0; //Disable all unmasked peripheral interrupt
OPTION_REG.INTEDG = 1; //Interrupt on rising edgeTRISB = 0xFF; //making portB as input
TRISC = 0×00; // making portC as output
TRISD = 0×00; // making portD as output
TRISA = 0×00; // making portA as outputADCON1 = 7; //Disable ADC so that PORTA can be used for digital purpose
CMCON = 7; //Disable comparatorPORTC = 0x0F; // initially the red light is on for pedestrian
PORTD = 0xF0; //initially the green light is on for vehicle
PORTA = 0×00;}
Thanks in advance…
Related Forum Messages
- PIC 16F877A PORTA Problem
- Help Reading PIN State
- Disabling interrupt in code vision avr
- Newbie interrupt problem
- LED BLINKING PIC16F877A
- PIC18f4550 usb VUmeter
- Interrupt Break
- TMR0L not counting up and not overflowing
- PIC16f877a port A problem simple lighting LED only
- PIC18F4550 whats wrong with D4-7
- A problem with programming pwm for pic16f877a in mikroC
- RB port change interrupt need some help
- First Program/circuit problems
- Interrupt does not return!!
- Decoding rc5 tv remote
- Please small help for pic16f877a
- Hi-Tech C Compiler: What am I doing wrong?
- Led_curtain program – problem solved
- My PIC18F4523 PROBLEMS!!??
- Okay MikroC isn’t helping program a P16F684
Hello again everyboy, I have a problem. When I use pins of PORTA as input, I want to check the PORTA.F0 is 1 or not. if I check the pins of porta 0,1,2 and 3 my code works.However if I check only PORTA.F0 is 1 or not, my code doesn't work. My code is below which is work; Code: Select all void main() { int i = 1; ADCON1 = 0x0F; /*Configure AN pins as digital*/ CMCON = 0x07; ...im totally new to this world, i got 16F877A, and tried to mod the LEDs example provided with mikroC but Failed to Read PORTA.RA0 State Code: Select all void main() { ANSEL = 0; // Configure AN pins as digital ANSELH = 0; C1ON_bit = 0; // Disable comparators C2ON_bit = 0; TRISA = 0xFF; // set direction to be input TRISB = 0x00; ...i tried to use interrupt INT0 of atmega16.. i wnt to disable interrupt once the program enters the INTERRUPT SUBROUTINE and enable the interrupt once the ISR gets over. but for the interruot to start for thr first time #asm("sei") needs to be given in the main().. i want to enavle interrut once and then disable it in the ISR.. i have given my code below. plz help.. interrupt [EXT_INT0] void ext_int0_isr(void) { #asm("cli"); delay_ms(4.752); for(i=0;ilt11;i++) { PORTC=PINDampamp0x04; PORTA=0x00; delay_us(864); PORTA=0x01; delay_us(864); } PORTA=0x00; delay_us(864); PORTA=0x02; delay_us(864); PORTA=0x00; } void main(void) { PORTA=0x00; DDRA=0xFF; PORTB=0x00; DDRB=0x00; PORTC=0x00; DDRC=0xFF; PORTD=0x00; DDRD=0x00; #asm("sei"); while (1) { // Place your code here }; }I'm really struggling to understand the interrupts. I could use some help please! My code is simple (below). What I want is to make a short pulse on PORTA.1 that is triggered by Trigger5ms(); and reset by the interrupt handler. Why doesn't this work? What am I missing? It seems I've tried everything! BTW, Im using EasyPIC5 and mikroC pro. Thanks, Doug --------- code ------------ unsigned int a = 0; unsigned short dd = 0; void interrupt() { if (PORTA != 0) { PORTA = 0; } else { PORTA = 1; } //INTCON.GIE = 0; INTCON.TMR0IE = 0; // disable TMR0 interrupt INTCON.TMR0IF = 0; // reset TMR0 interrupt flag - get ready for a new ...im a beginner in Mikro c for PIC. i used a example program for learning but i doesnt work i use crysal 4Mhz and use project setting for HS and crystal setting. please help me about my problem best regards javad void main(){ ADCON1=0x06; PORTA=0; PORTB=0; PORTC=0; PORTD=0; TRISA=0x00; TRISB=0x00; TRISC=0x00; TRISD=0x00; while(1){ PORTA=~PORTA; PORTB=~PORTB; PORTC=~PORTC; PORTD=~PORTD; delay_ms(1000); } }Hello, I have a problem with 18f4550 ports. For now I am trying the code below, but not all the leds light up. Any ideas why? Code: Select all unsigned char readbuff[5] absolute 0x500; // Buffers should be in USB RAM, please consult datasheet unsigned char writebuff[5] absolute 0x540; int v_res; char cnt; char kk; void interrupt(){ USB_Interrupt_Proc(); // USB servicing is done inside the interrupt } void init(){ CMCON = 7; ADCON1 = 0x0F; ...Hi All, I am hoping you can help me with this little problem. I am not sure if its due to my programming or a lack of AVR understanding. I have a number of different functions and I want them to change when an External Interrupt is pressed. My problem is not with the interrupt but what happens after the interrupt is activated. Although I increment a variable it continues to finish the function it was previously in before going to next function. Here is the code Code: Select all dim count as byte sub procedure Wait() Delay_ms(100) end sub 'effect functions sub procedure Cycle() 'to do end sub sub procedure ...Hello there. I am new with timers and I want to see timer0 overflowing and the value of TMR0L counting up. I got the code ready but not sure what I am missing. My code is below. Please help ! The main should start with initial value of 250 for TMR0L as long as INTCON.B2 TMR0IF is not set as 1. The TMR0L value should increase upto 255 and then overflow and start again from zero. After main() it should be again set to 255 and the last instruction clears the overflow flag. Code: void main() { TRISA = 0x00; // set direction to ...Hi, Can you help me? I can't make my porta.f4 light. There's no problem on other pins because they are showing a red signal on Proteus symbolizing that it outputs a logic 1. But I don't know why porta.f4 stay blue which outputs a logic 0. Here's my source code Code: Select all #define x1 porta.f0 #define x2 porta.f1 #define x3 porta.f2 #define x4 porta.f3 #define x5 porta.f4 #define x6 porta.f5 #define x7 porte.f0 #define x8 porte.f1 #define x9 porte.f2 #define x10 portc.f0 #define x11 portc.f1 #define x12 portc.f2 #define x13 portc.f3 #define x14 portd.f0 #define x15 portd.f1 #define x16 portd.f3 #define x17 portc.f4 #define x18 portc.f5 #define x19 portc.f6 #define x20 ...I can write 0 or 1 with PORTX.F# command, can u help why I fail to modify D4-7? Only D7 port is turned on, while others are zero. After a few runs the port values changes. The ports are turned on randomly. I use 18F4550 and my desire is to count 0000 to 1111 on ports D4-D5-D6-D7 but I fail except 0000. Here is the code. void main(void){ ADCON1 = 14; //Select AN0 as analog input and the others as digital output CMCON = 7; //COMPARATOR disabled TRISA = 0; // ALL ports are output TRISB = 0; TRISC = 0; TRISD = 0; TRISE = 0; PORTA = 0x00; ...Hi, I am trying to write quite a simple program for picf8771 in mikroC, but I am a beginner so I am facing some difficulties. I am using the PWM library and the idea is to change the pwm duty cycle by pressing the button connected to the RB0. The LED connected to RC2 is supposed to be controlled by the pwm output. This is my code: int cnt = 250; void main() { TRISB = 0xFF; TRISC = 0X00; PORTC = 0x00; TRISD=0x00; PORTD=0x00; ADCON1 = 0x7F; INTCON = 0xD0; OPTION_REG = 0x00; PWM1_Init(5000); while (1) { PWM1_Set_Duty(cnt); PWM1_Start(); delay_ms(500); } } void interrupt (void) { if (cntgt=255) cnt=0; else cnt+=50; PORTD=~PORTD; INTCON.INTF = 0; } Help, please. ThanksAfter I checked out datasheet for 16F887 (on EasyPIC5 devboard) I played with various functions so I finally got to RB port change interrupts. I think I initialised all the registers correctly (BTW- Mince's nice template was a good starting point as you can see in the following code). So, I got RB/INT external interrupt to work. No problem there. However I simply cannot get RB port change interrupt to work so any help is appreciated. I also have two questions related to RB port change and RB0/INT external interrupts. 1. What should be correct TRIS settings for those ...I am having trouble. (understatement) I have a 16F877 and have written a program to flash an LED, but its not working. I have also used example code, and I still cant get it to work. Here is a picture of my circuit and also the code used. The hex file is also included. URL for my picture http://s1233.photobucket.com/albums/ff388/modsbyus/ Code: Select all program LED_Blinking main: TRISA = 0x00 ' set direction to be output TRISB = 0x00 ' set direction to be output TRISC = 0x00 ...I have this code that basically its a 45 seg counter. I want to implement an interruption on it using RB4-RB7 interrupt type, when I press the push button the interrupts happens but not return to the main loop of the program. Code: Select all void interrupt(){ if (INTCON.RBIF){ PORTD=9; Delay_ms(1000); INTCON.RBIF=0; } } void main() { int i,k=0; INTCON.RBIE = 1; // enable on change interrupts INTCON.GIE = 1; // enable Global interrupts TRISC=0; PORTC=0; TRISD=0; PORTD=0; PORTB=0; TRISB=0xFF; do{ for(i=0;ilt=4;i++){ PORTC=i; if (i==4){ for(k=0;klt=5;k++){ ...i tried to decode phillips tv remote IR signal using atmega16 and TSOP 1738(ir reciever) 1st i used interrupts(INT0 - pin16th) to detect the 1st falling edge to syncronise the delays..but after it goes to the interrupt subroutine the falling edges in the input datastream is also considered as interrupt and the subroutine is repeated. suggest me some help to overcome this problem. can i use polling as an alternative to interrupts? if so how? please help. i am using code vision avr as my programming tool.. i am givvin my code: interrupt [EXT_INT0] void ext_int0_isr(void) { #asm("cli"); delay_ms(4.752); for(i=0;ilt11;i++) ...hi...i try tow write simple code for pic16f877a to run five phase stepper motor my code written by microbasic(7002) and try to simulate in proteus 7 but when run in proteus 7 error shown to me(processor has been reset by watchdog timer expireing in time 10:00)and dont work when i download in picmicrobasic code:program one_proceuremain: TRISB = $00 TRISD = $00 TRISC = $00 trisa = $00 PORTA=7 PORTB=0 ...I am trying to program a PIC16F877A. I know my hardware is good because I can load on the LED blink program from here: blink a LED and it works. I am trying to do an led blink program using the Hi-Tech C Compiler. I have it specified as the tool chain in MPLab. Here is my code: #include ltpic.hgt #include ltconio.hgt #include ltstdlib.hgt #include ltstdio.hgt #include ltctype.hgt #include "delay.h" //#include "delay.c" //void delay(void); //#define _16F877 // __CONFIG(UNPROTECT|BODEN|FOSC1|BKBUG|WRT); //__CONFIG( XT amp WDTDIS amp PWRTDIS amp BORDIS amp LVPDIS amp WRTEN amp DEBUGDIS amp UNPROTECT ); void main (){ ADCON1 =0x06 ; // Changes PORTA to digital CMCON = 0x07 ; // Disable analog comparators PORTA = 0x00 ...Found solution a few minutes later on a blog - it is actually pins being used after all: for the oscillator. Change j13 and set oscillator to allow ra6 and ra7 in picflash options. I would have deleted the message but can't .... ===================================== I have just purchased an Easypic6 and am testing out the sample programs which arrived with it. The led_curtain program works fine except that the leds ra6 and ra7 don't light. They will light when I press the buttons on the board. I am wondering if I am missing something - setting a switch somewhere? My first thought ...Hello,everybody.I wrote a simple LED blinking program using; PIC18F4523/XTAL=20MHZ/ compiler= uC PRO for PIC v 5.30. But it does'nt blink and work.!!?? Would you please tell me what is/are wrong with my LED blinking program or hardware circuit? [Here I attached my PROTEUS(PIC18F4523 LED blinking)hardware circuit and code.]. Code: Select all /* MCU: PIC18F4523. Osc: HS, 20.0000 MHz. SW: ...Alright well I got the PICkit 1 today, and the first thought that came through my mind, "Well alright the tutorials have got to be pretty useful!" After the first tutorial I was already lost in the example assembly source code (I got the code to compile and run on a PIC fine, it's just with Assembly I'm lost). So I tried going though the booklet and try to look at the documentation provided with the source code and kinda felt overwhelmed on how much I would have to remember and decided to go with something I know pretty well ...
