Search Results - mikroc

Home Forums Search Search Results for 'mikroc'

Viewing 15 results - 1 through 15 (of 37 total)
  • Author
    Search Results
  • #13782
    sonar_abhi
    Participant

    Hello Guys,

    I am trying to implement a delay using timer0 interrupt. I’ll just post an abstraction of the code in mikroc

    void inittimer()

    {

    //Timer initialization for a 32ms interrupt

    }

    void interrupt()

    {

    //interrupt code;

    delayvariable++;

    }

    void main()

    {

    TRISB = 0;          //PORTB is output

    TRISC.F0 = 1;   //PORTC Pin 0 is input and connected to a switch

    if (PORTC.F0 ==0) //check is the button is pressed

    {

    if (delayvariable==3)   //~100ms second delay to check buttton debounce

    {

    if (PORTC.F0==0) //check if the button is still pressed

    {

    PORTB = ~PORTB; //toggle PORTB

    delayvariable = 0;  //reset the delay variable

    }

    }

     

    }

    }

     

    The above code does not work as I expected. Can somebody please point out the mistake I am making or suggest a better way for achieving a 100 ms delay using interrupt?

     

     

    Ligo George
    Keymaster

    You can follow the tutorial, Interfacing Keypad with PIC Microcontroller. I think you will be using an LCD also in this project. If so you can display a menu in the LCD. Based on the menu you can select the direction of motor rotation. You can create one menu to adjust the speed or duty cycle of the PWM. Enter the value of duty cycle (0 ~ 100%) using the keypad.

    #13488
    Ligo George
    Keymaster

    It seems like you are trying to do RAM consuming operations (strings etc) in the interrupt routine. Just post your complete MikroC code here.

    Mouad Barzani
    Participant

    Hi, My Project is automatic irrigation
    When I build my program without interruption it works but when I add void interrupt it shows up a mistake “NOT ENOUGH RAM FOR STACK” as the picture and folders of MikroC show.

    #13453
    Ligo George
    Keymaster

    You can use MikroC program, hopefully it will work without any changes. But this MPLAB XC8 requires some changes.

    #13199
    Ligo George
    Keymaster

    You may use the following links as a reference.

    But you can’t use UART or I2C with 16F84A as there is no hardware module in it. You can try UART with MikroC Soft UART libraries.

    Sorry, currently we don’t have any reference for assembly language.

    #13113
    Ligo George
    Keymaster

    For interfacing LCD you can use our LCD library. Check the following link for that.

    Interfacing LCD with PIC Microcontroller – Hi-Tech C

    For relay interfacing coding is very simple. It is similar to controlling an LED. But in hardware you need to use a relay driver like ULN2803 IC or a simple transistor. Please refer the following link for that.

    Interfacing Relay with PIC Microcontroller – MikroC Pro

    You can easily code it for Hi-Tech C as the coding is very simple.

    #12550
    Ligo George
    Keymaster

    Sorry, we don’t have any MPLAB codes. You may convert MikroC codes to MPLAB using our PWM Library.

    Kimie Hakimie
    Participant

    hi and good day to you, i am working on pic16f877a , have interfaced push-button to trigger the ultrasonic sensor hc-sr04 and the range will control the motor speed by using the pwm function. i am very new to the programming mikroC and i really hope you can guide me. As now i just learn how to interface push button with my led. I tried to combine the code how to interfacing ultrasonic and lcd and it didn’t work, i am very sorry, here my code:

    void main()
    {
      TRISA.F0 = 1; //Configure 1st bit of PORTD as input
      TRISA.F1 = 1;
      TRISA.F2 = 1;
      TRISB.F5 = 0; //Configure 1st bit of PORTB as output
      TRISB.F6 = 0;
      TRISB.F7 = 0;
      TRISA.F3 = 0;
      PORTB.F5 = 1; //LED OFF
      PORTB.F6 = 1; //LED OFF
      PORTB.F7 = 1; //LED OFF
      PORTA.F3 = 1; //BUZ OFF
      ADCON1 = 7;
    
      do
      {
        // LED 1
        if(PORTA.F0 == 0) //If the switch is pressed
           PORTA.F3 = 0; //BUZ ON
        Delay_ms(100); //1 Second Delay
         PORTA.F3 = 1; //BUZ OFF
    
        {
          Delay_ms(150); //Switch Debounce
          if(PORTA.F0 == 0)//If the switch is still pressed
          {
            PORTB.F5 = !PORTB.F5; // LED out port
          }
        }
    
        // LED 2
      
        if(PORTA.F1 == 0) //If the switch is pressed
        if(PORTA.F0 == 0) //If the switch is pressed
           PORTA.F3 = 0; //BUZ ON
         Delay_ms(100); //1 Second Delay
         PORTA.F3 = 1; //BUZ OFF
        {
          Delay_ms(150); //Switch Debounce
          if(PORTA.F1 == 0)//If the switch is still pressed
          {
            PORTB.F6 = !PORTB.F6; // LED out port
          }
        }
    
    
        // LED 3
        if(PORTA.F2 == 0) //If the switch is pressed
        if(PORTA.F0 == 0) //If the switch is pressed
          PORTA.F3 = 0; //BUZ ON
        Delay_ms(100); //1 Second Delay
        PORTA.F3 = 1; //BUZ OFF
        {
          Delay_ms(150); //Switch Debounce
          if(PORTA.F2 == 0)//If the switch is still pressed
          {
            PORTB.F7 = !PORTB.F7; // LED out port
          }
        }
      }while(1);
    }
    emufambirwi
    Participant

    I am doing a project which requires that I turn on and off two LED’s independently from a computer using serial port communication. I send a character like ‘A’ via the serial port and turn on one LED for say 1 minute and send another character like ‘B’ and turn on another LED for 2 minutes. My problem is that when using Timer0 of pic 18F87k22, I can’t implement the 1 minute and 2 minute delays independently. When I turn on the one LED the other one doesn’t respond and vice versa. I am simulating using Proteus and my code is is in MikroC as shown below:

    char uart_rd;
    char cnt;
    
    void interrupt () 
    {
      if (TMR0IF_bit) 
      {
         cnt++;                 // increment counters
         TMR0IF_bit = 0;        // clear TMR0IF
    
         TMR0L = 0xDC;             // set TMR0 for aproximetly 1 sec
         TMR0H = 0x0B;
      }
    }
    
    void one_min_delay () 
    {
      TRISB  = 0;              // PORTB is output
      TMR0H = 0x0B;
      TMR0L = 0xDC;               // Timer0 initial value
    
      T0CON = 0x84;            // Set TMR0 to 8bit mode and prescaler to 256
      GIE_bit = 1;             // Enable global interrupt
      TMR0IE_bit = 1;          // Enable Timer0 interrupt
    
      cnt = 0;                 // Initialize cnt
    
      do 
      {
        if (cnt >= 60) 
        {
          LATB = 0x00;      // turnoff PORTB LEDs
          cnt = 0;             // Reset cnt
        }
      }while(1);
    }
    
    void two_min_delay () 
    {
      TRISB  = 0;              // PORTB is output
      TMR0H = 0x0B;
      TMR0L = 0xDC;               // Timer0 initial value
      T0CON = 0x84;            // Set TMR0 to 8bit mode and prescaler to 256
      GIE_bit = 1;             // Enable global interrupt
      TMR0IE_bit = 1;          // Enable Timer0 interrupt
    
      cnt = 0;                 // Initialize cnt
    
      do 
      {
        if (cnt >= 120) 
        {
          LATB = 0x00;      // turnoff PORTB LEDs
          cnt = 0;             // Reset cnt
        }
      }while(1);
    }
    
    void main() 
    {
      UART1_Init(9600);               // Initialize UART module at 9600 bps
      Delay_ms(100);                  // Wait for UART module to stabilize
      TRISB = 0x00;
    
      while (1) 
      {
        if (UART1_Data_Ready()) 
        {     // If data is received,
          uart_rd = UART1_Read();
        }
    
        if (uart_rd=='A')   
        {
          LATB = 0x01;
          one_min_delay();
        }
        else if (uart_rd == 'B')   
        {
          PORTB = 0x02;
          two_min_delay ();
        }
        uart_rd ='\0';
      }
    }
    
    #11858
    Ligo George
    Keymaster

    Hi,

    Sorry I don’t have any working code for it. But you can use string library as you are using MikroC.

    Use strstr() function to get a specific part of a string.

    #11857

    In reply to: PWM using PIC12F1572

    Ligo George
    Keymaster

    Hi,

    You can refer this tutorial : Generating PWM with PIC Microcontroller using CCP module – MikroC Pro

    Program will be same only as the compiler is MikroC but you need to change the IC in the project settings.

    XinC
    Participant

    Hi guys, I am kinda new to these forums and this is my first question.

    I need some help in writing the code to extract NMEA GPS coordinates, display them on a 2 by 16 LCD and send them via GSM for accident alert notification purposes. i have dealt with the GSM part (or at least i think so) but now i need to be able to send the coordinates from the location of the accident occurrence (accident alert system for vehicle project). To do that, i need to extract the coordinates from the $GPGGA line or $GPGLL line (or whichever works best). I need your help guys, I do not have much time left to finish the project. I am using PIC18F45k22 and for simulation of GPS I am using Virtual GPS that i have virtually linked with Proteus (v8.0). I would very much appreciate it if you could help me with a working code that i can integrate into the whole code.

    Thanks

    #11566
    Dmitry
    Participant

    Yes, i mean that article. I changed microcontroller in the MikroC project, also i changed //CMCON = 0x07;   // To turn off comparators for PIC16F877

    and insert C1ON_bit = 0; C2ON_bit = 0;     // Disable comparators for PIC16F887 and ANSEL  = 0x04; ANSELH = 0;             // Configure AN pins as digital I/O for PIC16F887. But nothing. Could you have a look at my code

    #11563
    Ligo George
    Keymaster

    I guess that you are referring to my article, Digital Clock using PIC Microcontroller.

    As that project using MikroC compiler, it should work without any changes in the program. But you should change the microcontroller in the MikroC project setting and REBUILD the project.

Viewing 15 results - 1 through 15 (of 37 total)
>