Archives
-
MikroEleKronika Timer 0 Problem
Hi All,
I’m trying to get my timer 0 interrupt to go in Mikro C Pro. I can’t seem to get it going. Even with their examples. I looked over the SFR’s and am pretty sure they’re right. I’m programming a PIC18F46J50. Any ideas?
Code:
void INIT(void);
unsigned int count = 0;
unsigned int LED_COUNT = 10;void interrupt(){
if(INTCON.TMR0IF)
{
count = count + 1;
INTCON.TMR0IF = 0;
}
}void main()
{
ADCON1 |= 0x0F; // Configure AN pins as digital
CM1CON1 |= 7; // Disable comparatorsRCON.IPEN = 1; //enabling priotity level on interrupts
INTCON2.TMR0IP = 1; //high priority level
INTCON.GIE = 1; //global interrupt enable
INTCON.PEIE = 1; //disable all peripheral interruptsT0CON.T08BIT = 1; //Timer0 is a 8 bit counter
T0CON.T0CS = 0; //increments w/ the internal clock
T0CON.PSA = 0; //prescalar assigned/enabled
T0CON.T0PS0 = 1; //Assign prescalar
T0CON.T0PS1 = 1;
T0CON.T0PS2 = 0;
INTCON.TMR0IE = 1; //enabling TMR0 interrupt on overflow
INTCON.TMR0IF = 0;
T0CON.TMR0ON = 1; //Timer0 is “ON”while(LED_COUNT > 1)
{
INIT();
}while(1)
{
Delay_ms(1);
}}
void INIT(void)
{TRISD = 0×00;
PORTD = 0×04;
Delay_ms(100);PORTD.RD2 = !PORTD.RD2;
Delay_ms(100);
LED_COUNT = LED_COUNT – 1;}
Related Forum Messages
- PIC18F46J50 Timer 0 Issue
- 1 second interrupt to blink a LED!!??
- PIC18F4550 DELPHI MICROC PRO HID USB TIMER interrupt…
- TROBLUES WITH TIMER0 CONFIGURATIONS
- Problems using the Stop watch
- Help with Mmc Read
- Presacler Help in Codes
- Timer0 Interrupt wrong interval
- Real Time Clock With PIC18F4550 using MikroC compiler
- USART receive interrupt
- Hello … Need Help With MMC And DAC to Play Wav Sound
- Using USB and UART simultaniously on PIC18F4550
- Pic18f452 tmr0 & interrupt problems
- Interrupts and MPLAB debug mode
- Problema con TIMER0
- Bug in simulator using PIC18F4550 timer0
- TMR0 & INTERRUPT PROBLEMS
- USB Example ON 18F2550
- DHCP init not working.
- Interrupt on PIC18f4550
Hi All, I"m new to Mikro C and can't get Timer 0 to count. I don't even enter my ISR. Must be something I'm overlooking. I've looked over my SFR's and those seem to be correct especially when looking at the examples provided for Timer 0 interrupts. Any have any ideas of where I'm coming short? Thanks Code: Select all void INIT(void); unsigned int count = 0; unsigned int LED_COUNT = 10; void interrupt(){ if(INTCON.TMR0IF) { count = count + 1; INTCON.TMR0IF = 0; } } void main() { ADCON1 |= 0x0F; ...Hello.I tested the following code using an interrupt to blink a LED in every 1 second. But,that does'nt work and does'nt blink.!!?? Would you please tell me what is wrong with the following code? Thanks, Code: Select all /* Here are the code and my hardware specifications; [ PIC18F452,XTAL=20MHZ,mikroC PRO for PICv5.6.1 ]. */ unsigned char counter=0;//Overflow counter. void interrupt(){ //Main Interrupt Service Routine(ISR). if(INTCON.TMR0IE ampamp INTCON.TMR0IF){ //Check if it is TMR0 Overflow ISR. ...Hello everyone. I desire to learn to change the timer settings in real time, not out, the timer stops after the adoption of team work .. *********************************************************** unsigned char k; unsigned char userWR_buffer[64], userRD_buffer[64]; int t0ctr=0; const char *text = "MIKROElektronika Compilers ER \r\n"; union { struct { unsigned TMR0ON : 1, T08BIT : 1, T0PS2 : 1, T0PS1 : 1, T0PS0 : 1; //TMR0H : 1, //TMR0L : 1; }bite; unsigned char byte; }timer; //************************************************************************************************** // Main Interrupt Routine //************************************************************************************************** void interrupt() { asm CALL _Hid_InterruptProc asm nop if(INTCON.TMR0IF) { //t0ctr++ ; //if(t0ctr==20+3){ PORTD.RD0=~PORTD.RD0; //t0ctr=0; //} INTCON.TMR0IF = 0 ...Hi guys; I have sat the next configuration to make a simple clock program for LCD, here is a little explication: main program i configurated all registers was necesary, INTCON, ADCON0 and 1 and TCON. Then this happen the program get in on endless loop (while(1)), when the timers gets the overflow this goes to funtion void interrupt(), inside I reload again the TMR0H = 61629 clear interruption INTCON.TMR0IF=0 then i count 60 overflows, this means 1 minute, the formula I used to calculate the TMR0H value is: Cristal 4Mhz Prescaler 256 set 16bit counter time overflow 1 second (1 ...Hi all I have a problem understanding how to use the stop watch in the simulator I set a break point in the ISR routine and a break point in the Init function at the very last instruction,I then run the code to the break point ,then I clear the stop watch and start the simulator in this case the code should stop at the break point in the ISR when the ISR(interrupt) is fired to allow me to read the time or cycles between interrupts this is exactly my problem in the simulator the Interrupt is never fired but in real time on real ...Hello all, I use the PIC18F4520 and the compiler "micro C Pro". My goal is to "load" the counter(TMR0) via the SD card. But i have two main problems. Below is the code: Code: Select all unsigned int size, kp; sbit Mmc_Chip_Select at LATC0_bit; sbit Mmc_Chip_Select_Direction at TRISC0_bit; /////////////---------------Read from file-----------------///////////////////// void M_Open_File_Read() { int digit; char filename[6] = "B.TXT"; MMc_Fat_Assign(ampfilename,0); Mmc_Fat_Reset(ampsize); Mmc_Fat_Read(ampdigit); EEPROM_Write(0x00,digit); ...i'm using PIC18F452 in my simulation and it works fine but when changing in PIC16F877A the "Symbol T0CON" is not working in 77A.. is there a difference between this PIC even they have same pins and timers? i'm using proton ide. here's the Code: Code: Device = 18F452 XTAL=20 Symbol T0E T0CON.7 Symbol T0CS T0CON.5 Symbol T0PSA T0CON.3 Symbol T0PS2 T0CON.2 Symbol T0PS1 T0CON.1 Symbol T0PS0 T0CON.0 Symbol GIE INTCON.7 Symbol TMR0IE INTCON.5 Symbol TMR0IF INTCON.2 Symbol LED PORTC.0 T0CS=0 'internal clock 20MHz/4 T0PSA=0 'Enable pre scaling T0PS0=1 'Prescaler 000 = 1:256 T0PS1=1 T0PS2=1 T0E=1 'Enable TMR0 Dim x As Byte ' to count interrupts Output PORTC PORTC=0 on_interrupt GoTo jingle GoTo start jingle: x=x+1 If x=76 Then Toggle LED x=0 EndIf TMR0IF=0 Context Restore start: TMR0IE=1 'enable TMR0 Interrupt GIE=1 loop: GoTo loop a littlebit confused,. if the program ...I don't know what is going on I'm trying to interrupt my code every 1 second. It is working with an 12MHz external oscillator. But the interrupt is occuring about a 1,4 interval. Can you help me please? The timer part code: Code: Select all void interrupt(){ if(INTCON.TMR0IF) { segundo--; INTCON.TMR0IF = 0; T0CON.TMR0ON = 1; } void main() { hora = 0; minuto = 0; segundo = 59; TRISA = 0xC7; INTCON = 0xE0; T0CON = 0x05; TMR0H = 0x48; TMR0L = 0xE5; T0CON.TMR0ON=1; }Hello !!! I am using PIC18F4550 for generating a real time clock by using timer0 interrupt. I have the following code which compiles successfully on MikroC compiler but on testing on proteus it is not giving any results. I have tried to change a lot of things and I have tried to research on how to solve this problem but am still facing the same problem. So can someone help me with this... unsigned int counter; unsigned int sec; unsigned int mins; unsigned int hour; unsigned int day; void interrupt() { if(INTCON.TMR0IF) { // if timer 0 overflow counter++ ; if(counter==3907) { // one second has elapsed counter = 0 ; sec++ ...Hello, I try to set up an interrupt routine to receive data while i am busy with other tasks MCU is PIC18F4620 at 8 MHz and easy pic6 Here is the INIT portion of the program before main start Code: Select all sub procedure Init_Main ADCON1.b0 = 0 ' set bits ...Hi All now i build a program to run a wave files wave file type is Mono / Bits / 16 KHz i do every things goood reading from memory and send a byte i have read to PORTB but my problem to play it in speaker i know that's need DAC but any body can help me on this ?????? this is my Code Code: #define LINE_LEN 43 #define CFILE_EXIST 1 #define CTMR0H 0xFE #define CTMR0L 0xD4 sfr sbit Mmc_Chip_select at LATC0_bit; sfr sbit Mmc_Chip_Select_Direction at TRISC0_bit; sfr sbit Out_LED_Green at LATC1_bit; sfr bit Out_LED_Red at LATC2_bit; unsigned char AudioFile[7]; char iSample; long int size; char bTimerInt; void Main_Init() { ...Hi everybody!! I'm using the PIC 18F4550 to establish communication between a GSM module and a PC. The USB communication works perfectly, however I can't get the Serial communication to work. I'm using a 8MHz cristal. I can't send data through the Tx pin but I can't get any data back. I noticed that an interruption occurs when a data is received but the data is not correct. here is my code: Code: Select all char uart_rd ='0'; char error = '0'; unsigned char Read_buffer[64]; unsigned char Write_buffer[64]; unsigned char num,i; void interrupt() { HID_InterruptProc(); ...Hello,everybody.I write a program to measure the input signal frequency by using an TMR0 interrupt and A function to display it on a LCD.But my TMR0 interrupt function does not send counter varaiable[cntr] to my displaying funtion or maybe not worked well,because I have only ; FRQ.= 00000 HZ on my LCD,[I test my funtion of FRQ. displaying by writting cntr=45678,then it displayed it on my LCD.So ,my Tmr0 interrupt function is not worked prioperly.]. At the following are myTMR0 interrupt function in two way but does not worked none of them. Would you please help me to correct it? My TMR0 interrupt functions; PIC18F452,XTAL;20MHZ 1.way ...I have been running some code under the MPLAB debugger with the Junebug. I was trying to teach myself how to use interrupts, mainly from the 18F1320 datasheet rather than code online. Although slow, the debugger is pretty neat, even if the one breakpoint limit sucks. I spent a while going crazy though as my breakpoint in the ISR didn't ever hit. I read something vague online that suggested interrupts don't fire if using debug mode. Is this correct? The same code with GIE and TMR0IE disabled and a simple test of the overflow flag works and provides a delay. The LED ...Hola; Tengo un problema al configurar el TIMER0, el timer lo configuro para que se desborde cada segundo para esto tengo entendido que tengo que usar la sig formula: estoy usando el prescaler a 256, el contador a 16 bits=65536, si fuera a 8 seria=256, el 1000000 es por que es is egundo pero debe estar en microsegundos, osea 1000000microsegundo TMRO= 65536-(1000000/(4*.25*256)), lo que debo cargarle al timer es 61629, para que se desvorde a 1 segundo en la rutina de interrupt(), lo vuelvo a cargar y limpio labandera, en el programa cada ves que se genera la int por ...I am using MPLAB X 1.41 on OS X 10.7.4 and have run into the following issue: 16 bit timer0 overflows do not trigger interrupts as they should. Simulating the following test code with a breakpoint on line 13 (bcf INTCON,TMR0IF) will only trigger the breakpoint once, then the code will run infinitely without hitting the breakpoint again. Uncommenting line 20 (bsf T0CON,T08BIT) to make the timer run in 8 bit mode and simulating results in the expected repeated interrupts. list p=18f4550 include p18f4550.inc config FOSC=HSPLL_HS, PLLDIV=2, CPUDIV=OSC1_PLL2, ...Hello,everybody.I write a program to measure the input signal frequency by using an TMR0 interrupt and A function to display it on a LCD.But my TMR0 interrupt function does not send counter varaiable[cntr] to my displaying funtion or maybe not worked well,because I have only ; FRQ.= 00000 HZ on my LCD,[I test my funtion of FRQ. displaying by writting cntr=45678,then it displayed it on my LCD.So ,my Tmr0 interrupt function is not worked prioperly.]. At the following are myTMR0 interrupt function in two way but does not worked none of them. Would you please help me to correct it? My TMR0 interrupt functions; PIC18F452,XTAL;20MHZ 1.way ...Hello everyone, I can't get the USB example to work on PIC18F2550. I am using EasyPIC6 board. My code compiles fine and I can program the chip with no problem but after that the HID device doesn't show in the device manager (windows xp) I am suspecting something is wrong with my configuration My code and configuration are as follows: Code: Select all #include "USBdsc.c" unsigned char Read_buffer[64]; unsigned char Write_buffer[64]; unsigned char num; // // Timer interrupt service routine // void interrupt() { USB_Interrupt_Proc(); // Keep alive TMR0L = 100; ...Hi, this is my code Code: Select all //############################################################################## // INTERRUPT OPERATIONS (Kesme islemleri) //############################################################################## void interrupt(void){ U8 i; if(INTCON.TMR0IF == 1){ SPI_Ethernet_userTimerSec++; TMR0L = 0; TMR0H = 0; INTCON.TMR0IF = 0; } } //############################################################################## // PORT_INIT //############################################################################## void Port_Init (void){ PORTA=0; LATA=0; ADCON0 = 0X00; ADCON1 = 0b00001110; // AN0 AN1 AN2 analog inputs.AVDD AVSS referance voltage. ADCON2 = 0b10111110; TRISA=0b00000001; PORTB=0; LATB=0; TRISB=0b00000001; PORTC=0; LATC=0; TRISC=0b10000000; PORTD=0; LATD=0; TRISD=0b01101001; PORTE=0; LATE=0; TRISE=0b00000000; ...Hi guys, yesterday i started working on a project which must involve at least 2 timers and i wanted to use pic18f4550, the datasheet tells me about high and low priority, i placed the timers at high priority. I followed the datasheet and made a test code for only timer0. But it didn"t work. I realy need your help. Im using mikro c for pic , here is what i have done: unsigned char george = 0; void interrupt(){ if(intcon.tmr0if){ george++; intcon.tmr0if = 0; } if(pir1.tmr1if){ pir1.tmr1if = 0; } if(pir1.tmr2if){ pir1.TMR2IF = 0; } } void configuration(void) { trisb = 0; portb = 0x0f; // set internal oscillator to 8Mhz osctune.tun4 = 0; osctune.tun3 = 1; osctune.tun2 = 1; osctune.tun1 = ...
