Search Results - microcontroller

Home Forums Search Search Results for 'microcontroller'

Viewing 15 results - 61 through 75 (of 127 total)
  • Author
    Search Results
  • #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

    #11801
    Ligo George
    Keymaster

    Hi,

    I think you should go for a small microcontroller for that. Otherwise it will be very difficult to make it with simple digital circuits. Using a small microcontroller will reduce the cost, complexity etc.

    sandeep
    Participant

    Hi sir,
    As I am learning SPI, i thought of interfacing two microcontrollers using SPI protocol, by passing a data in master and retrieving in the slave microcontroller.

    The code is as given below, the problem is I send a data of 0x05, and I get a different output on the slave microcontroller. I use PIC 16F877A microcontroller.

    //master code
    #include <htc.h>
    #include <pic.h>
    #include <stdio.h>
    #include <stdlib.h>
    __CONFIG_3F31;
    
    // __CONFIG(INTCLK & WDTDIS & PWRTDIS & MCLRDIS & UNPROTECT & DUNPROTECT & BORDIS & IESODIS & FCMDIS & LVPDIS);__CONFIG(BORV40);
    
    // function prototypesvoid init_io(void);
    void initialise_SPI(void);
    void spi_w(unsigned char data);
    void init_io(void)
    {
      TRISA = 0x01;
      TRISB = 0x01; // bit 0 = output, 1 = input
      TRISC = 0b10010111;
      TRISD = 0x00;
      TRISE = 0x00;
    }
    //SPI write command function
    void spi_w(unsigned char data)
    {
      unsigned char x;
      PORTC,RC6=0;
      while (!SSPIF); //wait for transmission complete
      x=SSPBUF; //dummy read
      SSPBUF=data;
      while (!SSPIF); //wait for transmission complete
      x=SSPBUF;
      PORTC,RC6=1;
    }
    void initialise_SPI(void)
    {
      SSPEN = 0;
      SSPSTAT=0b01000000;
      SSPCON=0b00100010;
      SSPEN = 1;
    }
    void main()
    {
      unsigned char data= 0x05;
      init_io();
      initialise_SPI();
      while(1)
      {
        spi_w(data);
        PORTD=data;
      }
    }
    
    //slave code
    
    void initialise_SPI(void);
    unsigned char spi_r(void);
    void init_io(void)
    {
      TRISA = 0b00100000;
      TRISB = 0x00;
      TRISC = 0b00011000;
      TRISD = 0x00;
      TRISE = 0x00;
    }
    void initialise_SPI()
    {
      SSPEN = 0;
      SSPSTAT=0b01000000;
      SSPCON=0b00100100;
      SSPEN = 1;
    }
    
    unsigned char spi_r()
    {
      unsigned char temp;
      PORTA,RA5= 0;
      while(!SSPIF);
      temp=SSPBUF;
      while(!SSPIF);
      temp=SSPBUF;
      PORTA,RA5 =1;
      return temp;
    }
    void main ()
    {
      unsigned char temp ;
      init_io();
      initialise_SPI();
      while(1)
      {
        temp=spi_r();
        PORTD=temp;
      }
    }
    
    #11756
    mustunsultan
    Participant

    Hello,
    I am new to PIC Microcontrollers, but have gone through all the tutorials.  I can write codes on my own for PWM and ADC seperately. But when I try to use both at the same time I don’t get any output signal at CCP1 *checked with Proteus also*

    I am trying to use 2 buttons RC4 and RC5 to increase and decrease the PWM duty cycle. And use ADC for lighting up LEDs , but I can get any signal out of CCP1.

    Here is the code I tried:

    unsigned int ADC;
    
    void main()
    {
      short duty1 = 16;
    
      CMCON = 0x07;
      ADCON1 = 0x80;
    
      TRISA = 0xFF;    //input analog signal
      TRISC = 0x30;    //RC4 RC5 input button, RC2 output PWM
      TRISB = 0x00;    //output MSB's of ADC
      TRISD = 0x00;    //output LSB's of ADC
    
      //ADC Function
      do
      {
        ADC = ADC_Read(1);
        PORTB = ADC;
        PORTD = ADC>>2; 
      }
      while(1);
    
      ////////////////////////////////////////////////
    
      //PWM Function
      PWM1_Init(5000);
      PWM1_Start();
      PWM1_set_duty(duty1);
    
      while(1) 
      {
        if (PORTC.F4 == 0) 
        {
          Delay_ms(1);
          duty1++;
          PWM1_set_duty(duty1);
        }
        if (PORTC.F5 == 0)
        {
          delay_ms(1);
          duty1--;
          PWM1_set_duty(duty1);
        }
        delay_ms(100);
      }
    }
    
    #11665
    Ligo George
    Keymaster

    You can use the CCP module of PIC Microcontroller for that. Check for the PWM generating functions in CCS C.

    All most all of the remote works in 38KHz.

    #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.

    Dmitry
    Participant

    I try to change PIC16F877. I need use PIC16F887, but i can’t get properly data of time/date.  Although for PIC16F877 everything fine. What i need to do to use PIC16F887 microcontroller?

    manjula
    Participant

    I would like to make a PWM LED light system, with PORTA & PORTB of 16F628A.
    I want to shift to A+B Port with pwm night rider shadow LED program

    void main()
    {
      CMCON = 0x07; // To turn off comparators
      ADCON1 =0x06; //Turne off adc
      TRISB = 0x00; // Sets all pins in PORTB as output
      PORTB = 0b00000001; // Set RB0 to high 00000001
      TRISA = 0x00; // Sets all pins in PORTB as output
      PORTA = 0b00000000; // Set RB0 to high 00000001
    
      do // To set infinite loop
      {
        Delay_ms(100); // 300 mili seconds delay
        PORTA = PORTA<<1; //Shifting right by one bit
        if(PORTA >= 0b10000000) //To reset to 00000001
        {                          //when the count becomes 10000000
          Delay_ms(100);
          PORTA = 0b00000000
          PORTB = 0b00000001
        }
        if(PORTB >= 0b00000001) //If RB7 =1
        {
          Delay_ms(100);
          PORTB = PORTB<<1; //Shift one bit right
          if(PORTB >= 0b10000000) //To reset to 00000001
          {
            Delay_ms(100); //
            PORTB =0b00000000; //RB low
            PORTA =0b00000001;
          }
        }
      }while(1); // To set infinite loop
    }
    #11538

    In reply to: PWM by pic 16F877A

    Shubham
    Participant

    Hi Ligo

    i want a generate a pulse with 1 uS ON time. the total time period is 255 uS. the duty cycle for this wave is 0.003984. but when i try to stimulate it in proteus the ON period comes out to be 0.1 uS. the code which i have written is as follows:

    void main(void)
    {
    TRISC2_bit=0;
    PWM1_Init(3920);
    PWM1_Start();
    while(1)
    {
    PWM1_Set_Duty(0.09996);
    }
    }

    please help me out as i m novice in using PIC Microcontroller.

    #11510
    Chibundu
    Participant

    With reference to the article Digital Clock using PIC Microcontroller and DS1307 RTC. Can anyone help me with the explanation of setting hour in the switch case 1 ?

    // LCD module connections
    sbit LCD_RS at RB2_bit;
    sbit LCD_EN at RB3_bit;
    sbit LCD_D4 at RB4_bit;
    sbit LCD_D5 at RB5_bit;
    sbit LCD_D6 at RB6_bit;
    sbit LCD_D7 at RB7_bit;
    sbit LCD_RS_Direction at TRISB2_bit;
    sbit LCD_EN_Direction at TRISB3_bit;
    sbit LCD_D4_Direction at TRISB4_bit;
    sbit LCD_D5_Direction at TRISB5_bit;
    sbit LCD_D6_Direction at TRISB6_bit;
    sbit LCD_D7_Direction at TRISB7_bit;
    // End LCD module connections
     
    unsigned short read_ds1307(unsigned short address)
    {
      unsigned short r_data;
      I2C1_Start();
      I2C1_Wr(0xD0); //address 0x68 followed by direction bit (0 for write, 1 for read) 0x68 followed by 0 --> 0xD0
      I2C1_Wr(address);
      I2C1_Repeated_Start();
      I2C1_Wr(0xD1); //0x68 followed by 1 --> 0xD1
      r_data=I2C1_Rd(0);
      I2C1_Stop();
      return(r_data);
    }
    
    void write_ds1307(unsigned short address,unsigned short w_data)
    {
      I2C1_Start(); // issue I2C start signal
      //address 0x68 followed by direction bit (0 for write, 1 for read) 0x68 followed by 0 --> 0xD0
      I2C1_Wr(0xD0); // send byte via I2C (device address + W)
      I2C1_Wr(address); // send byte (address of DS1307 location)
      I2C1_Wr(w_data); // send data (data to be written)
      I2C1_Stop(); // issue I2C stop signal
    }
    
    unsigned char BCD2UpperCh(unsigned char bcd)
    {
      return ((bcd >> 4) + '0');
    }
    
    unsigned char BCD2LowerCh(unsigned char bcd)
    {
      return ((bcd & 0x0F) + '0');
    }
    
    int Binary2BCD(int a)
    {
      int t1, t2;
      t1 = a%10;
      t1 = t1 & 0x0F;
      a = a/10;
      t2 = a%10;
      t2 = 0x0F & t2;
      t2 = t2 << 4;
      t2 = 0xF0 & t2;
      t1 = t1 | t2;
      return t1;
    }
     
    int BCD2Binary(int a)
    {
      int r,t;
      t = a & 0x0F;
      r = t;
      a = 0xF0 & a;
      t = a >> 4;
      t = 0x0F & t;
      r = t*10 + r;
      return r;
    }
    
    int second;
    int minute;
    int hour;
    int hr;
    int day;
    int dday;
    int month;
    int year;
    int ap;
    
    unsigned short set_count = 0;
    short set;
     
    char time[] = "00:00:00 PM";
    char date[] = "00-00-00";
    
    void main()
    {
      I2C1_Init(100000); //DS1307 I2C is running at 100KHz
      CMCON = 0x07;   // To turn off comparators
      ADCON1 = 0x06;  // To turn off analog to digital converters
      TRISA = 0x07;
      PORTA = 0x00;
      Lcd_Init();                        // Initialize LCD
      Lcd_Cmd(_LCD_CLEAR);               // Clear display
      // Lcd_Cmd(_LCD_CURSOR_OFF);          // Cursor off
      Lcd_Cmd(_LCD_BLINK_CURSOR_ON);
      Lcd_out(1,1,"Time:");
      Lcd_out(2,1,"Date:");
    
      do
      {
        set = 0;
        if(PORTA.F0 == 0)
        {
          Delay_ms(100);
          if(PORTA.F0 == 0)
          {
            set_count++;
            if(set_count >= 7)
            {
              set_count = 0;
            }
          }
        }
        if(set_count)
        {
          if(PORTA.F1 == 0)
          {
            Delay_ms(100);
            if(PORTA.F1 == 0)
              set = 1;
          }
          if(PORTA.F2 == 0)
          {
             Delay_ms(100);
             if(PORTA.F2 == 0)
               set = -1;
          }
          if(set_count && set)
          {
            switch(set_count)
            {
              case 1:
                      hour = BCD2Binary(hour);
                      hour = hour + set;
                      hour = Binary2BCD(hour);
                      if((hour & 0x1F) >= 0x13)
                      {
                        hour = hour & 0b11100001;
                        hour = hour ^ 0x20;
                      }
                      else if((hour & 0x1F) <= 0x00)
                      {
                         hour = hour | 0b00010010;
                         hour = hour ^ 0x20;
                      }
                      write_ds1307(2, hour); //write hour
                      break;
              case 2:
                      minute = BCD2Binary(minute);
                      minute = minute + set;
                      if(minute >= 60)
                        minute = 0;
                      if(minute < 0)
                        minute = 59;
                      minute = Binary2BCD(minute);
                      write_ds1307(1, minute); //write min
                      break;
              case 3:
                      if(abs(set))
                      write_ds1307(0,0x00); //Reset second to 0 sec. and start Oscillator
                      break;
              case 4:
                      day = BCD2Binary(day);
                      day = day + set;
                      day = Binary2BCD(day);
                      if(day >= 0x32)
                        day = 1;
                      if(day <= 0)
                        day = 0x31;
                      write_ds1307(4, day); // write date 17
                      break;
              case 5:
                      month = BCD2Binary(month);
                      month = month + set;
                      month = Binary2BCD(month);
                      if(month > 0x12)
                        month = 1;
                      if(month <= 0)
                        month = 0x12;
                      write_ds1307(5,month); // write month 6 June  
                      break;
              case 6:
                      year = BCD2Binary(year);
                      year = year + set;
                      year = Binary2BCD(year);
                      if(year <= -1)
                        year = 0x99;
                      if(year >= 0x50)
                        year = 0;
                      write_ds1307(6, year); // write year
                      break;
            }
    
          }
        }
    
        second = read_ds1307(0);
        minute = read_ds1307(1);
        hour = read_ds1307(2); 
        hr = hour & 0b00011111; 
        ap = hour & 0b00100000;
        dday = read_ds1307(3);
        day = read_ds1307(4);
        month = read_ds1307(5);
        year = read_ds1307(6);
    
        time[0] = BCD2UpperCh(hr);
        time[1] = BCD2LowerCh(hr);
        time[3] = BCD2UpperCh(minute);
        time[4] = BCD2LowerCh(minute);
        time[6] = BCD2UpperCh(second);
        time[7] = BCD2LowerCh(second);
    
        date[0] = BCD2UpperCh(day);
        date[1] = BCD2LowerCh(day);
        date[3] = BCD2UpperCh(month);
        date[4] = BCD2LowerCh(month);
        date[6] = BCD2UpperCh(year);
        date[7] = BCD2LowerCh(year);
    
        if(ap)
        {
          time[9] = 'P';
          time[10] = 'M';
        }
        else
        {
          time[9] = 'A';
          time[10] = 'M';
        } 
        Lcd_out(1, 6, time);
        Lcd_out(2, 6, date);
        Delay_ms(100);
      }while(1);
    }
    
    #11484
    Ligo George
    Keymaster

    Are you sure that you are using push switch ?

    If you are using push switch, the sequence will not repeat without pressing of switch.

    Most of the microcontroller programs requires infinite loop as it needs to continuously read sensor status, switch status etc.

    #11467
    ericJ
    Participant

    I am trying to connect 127 switches to the microcontroller using three 74ls138  decoders how will I scan the switch for buttons pessed

    #11457
    Ligo George
    Keymaster

    Just read the above tutorials carefully, you can do it yourself. You can connect two switches to any of the IO pins of PIC Microcontroller. You can make those pins Input by writing to TRIS register. Similarly you can connect L293D inputs to 2 outputs of MCU and make those pins Output by writing to TRIS register.

Viewing 15 results - 61 through 75 (of 127 total)
>