EngineersGarage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Advertise
You are here: Home / Topics / Creating hex file problem

Creating hex file problem

|

Miscellaneous › Others › Creating hex file problem

  • This topic has 2 replies, 3 voices, and was last updated 8 years, 1 month ago by Ashutosh Bhatt.
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • February 24, 2016 at 12:12 pm #4319
    Navneet
    Participant

    Please help me out in creating the hex file for this code. I have tried using MPLAB using xc 8 compiler. but its showing error. timers.h header file is not found. If possible please help me in converting this to hex file. i need it urgently for my final semester project

     

    #include <p18f4550.h>
    #include <timers.h>
     
    //======================= chip config ===================//
    #pragma config PLLDIV = 1          
    #pragma config CPUDIV = OSC1_PLL2                            
    #pragma config FOSC = HSPLL_HS
    #pragma config USBDIV = 1          
    #pragma config IESO = OFF        
    #pragma config PWRT = OFF        
    #pragma config BOR = OFF        
    #pragma config VREGEN = OFF  
    #pragma config WDT = OFF     
    #pragma config WDTPS = 32768     
    #pragma config CCP2MX = ON       
    #pragma config PBADEN = OFF      
    #pragma config LPT1OSC = OFF         
    #pragma config MCLRE = ON            
    #pragma config STVREN = ON       
    #pragma config LVP = OFF     
    #pragma config ICPRT = OFF       
    #pragma config XINST = OFF       
    #pragma config DEBUG = OFF
    #pragma config WRTD = OFF
    //======================= chip config ===================//
     
    //LCD Control pins
    #define rs PORTBbits.RB4
    #define rw PORTBbits.RB3
    #define en PORTBbits.RB2
     
    //LCD Data pins
    #define lcdport PORTD
    #define lcd_port_dir TRISD
     
    void lcd_clear ( void );
    void lcd_2nd_line ( void );
    void lcd_1st_line ( void );
    void lcd_ini ( void );
    void dis_cmd ( unsigned char cmd_value );
    void dis_data ( unsigned char data_value );
    void lcdcmd ( unsigned char cmdout );
    void lcddata ( unsigned char dataout );
    void delay_ms ( int delay );
     
     
    //============================ TIMER 0 ISR =================================//
    #pragma interrupt tmr0_interrupt
    void tmr0_interrupt(void)
    {
       unsigned int v = 0; 
     
       ADCON0 |= 0x02;                 // Start A/D conversion
       while ( ADCON0 & 0x02 );        // Wait until conversion gets over
      
       v = ADRESH;
       v = v << 8;
       v |= ADRESL;
       
       if ( ( v > 1 ) && ( v < 100 ) )
       {   
        CCP1CON |= ( ( v & 0x03 ) << 4 );
        CCPR1L = v >> 2;
       }
       else;
     
       INTCONbits.TMR0IF=0;
    }
    //============================ TIMER 0 ISR =================================//
     
    void adc_init(void)
    {
        TRISA |= 0x01;            // Configure RA0 as input pin
        LATA = 0;
        
        ADCON1=0x0E;                            // Make RA0/AN0 pin as analog pin (Other pins remain to be digital I/O)
        ADCON0=0x00;                            // Select Channel0 & ADC off
        ADCON2=0x80;                            // Right justified, 0TAD, Fosc/2 clock option
        ADCON0bits.ADON = 1;                    // Enable ADC
    }
     
    void main ( void )
    {
     
    unsigned char data1 [] = "EngineersGarage";
    unsigned char data2 [] = "  AUDIO IN OUT ";
    int i = 0;
     
    OSCCON = 0x0C;
     
    lcd_ini (); // LCD initialization
     
    delay_ms ( 200 );
     
    //========================= start up display on LCD ================================//
    while ( data1 != '' )
    {
    dis_data ( data1 );
    delay_ms ( 200 );
    i++;
    }
    i = 0;
     
    lcd_2nd_line ();
     
    while ( data2 != '' )
    {
    dis_data ( data2 );
    delay_ms ( 200 );
    i++;
    }
    i = 0;
    //========================= start up display on LCD ================================//
     
    //============================ PWM SETTINGS ====================================//
    TMR2 = 0x00; // setting TMR2 value as 0, start counting from 0
    PR2 = 22; // set the PR2 value, to get PWM period of 2us
    CCPR1L = 0x00; // setting initial value of CCPR1L as 0
    CCP1CON = 0x0C; // select single output with P1A, and mode select bits so as to get P1A, P1B,
    P1C and                                    // P1D as active-high
    TRISC &= 0xFB; // setting the PWM pin as output
    T2CON = 0x04; // both the pre-scalar and post-scalar bits are written for 1:1 with the
    timer2 turned on.
     
    INTCONbits.T0IF = 0; // turning off the Timer0 interrupt
    TMR0L = 0xFE; // setting the timer register to value 
    T0CON = 0xC0; // enable the timer, select the timer in 8bit, select CLKO, assign
    the pre-scale value 1:4
    INTCONbits.TMR0IF=0; // clearing the timer0 overflow bit
    INTCONbits.T0IE = 1; // enabling the timer0 interrupt
    INTCONbits.GIE = 1; // enabling the global interrupts
    //============================ PWM SETTINGS ====================================//
     
    adc_init ();
     
    while ( 1 )
    {
    ;
    }
     
    }
     
     
    //======================== LCD routines defenitions ========================//
     
    void delay_ms ( int delay )
    {
    int ms, i;
     
    for ( ms = 0; ms < delay; ms ++ )
    for ( i = 0; i < 70; i ++ );
    }
     
    void lcd_ini ( void )                    
    {
    TRISB &= 0xE3;
    lcd_port_dir &= 0x0F;
    dis_cmd ( 0x02 ); // to initialize LCD in 4-bit mode.
    dis_cmd ( 0x28 ); //to initialize LCD in 2 lines, 5X7 dots and 4bit mode.
    dis_cmd ( 0x0C );
    dis_cmd ( 0x06 );
    dis_cmd ( 0x80 );
    dis_cmd ( 0x01 );
    delay_ms ( 500 );
    }
     
    void dis_cmd ( unsigned char cmd_value )
    {
    unsigned char cmd_value1;
    cmd_value1 = cmd_value & 0xF0; //mask lower nibble because PA4-PA7 pins are used. 
    lcdcmd ( cmd_value1 );         // send to LCD
    cmd_value1 = ( ( cmd_value << 4 ) & 0xF0 ); //shift 4-bit and mask
    lcdcmd ( cmd_value1 ); // send to LCD
    }
     
    void dis_data ( unsigned char data_value )
    {
    unsigned char data_value1;
    data_value1 = data_value & 0xF0;
    lcddata ( data_value1 );
    data_value1 = ( ( data_value << 4 ) & 0xF0 );
    lcddata ( data_value1 );
    }
     
    void lcdcmd ( unsigned char cmdout )
    {
    lcdport &= 0x0F;
    lcdport |= cmdout;
    rs = 0;
    rw = 0;
    en = 1;
    delay_ms ( 50 );
    en = 0;
    delay_ms ( 50 );
    }
     
    void lcddata ( unsigned char dataout )
    {
    lcdport &= 0x0F;
    lcdport |= dataout;
    rs = 1;
    rw = 0;
    en = 1;
    delay_ms ( 50 );
    en = 0;
    delay_ms ( 50 );
    }
     
    void lcd_clear(void)
    {
    dis_cmd(0x01);
    delay_ms(10);
    }
     
    void lcd_2nd_line(void)
    {
    dis_cmd(0xC0);
    delay_ms(1);
    }
     
    void lcd_1st_line(void)
    {
    dis_cmd(0x80);
    delay_ms(1);
    }
     
    //======================== LCD routines defenitions ========================//
    March 31, 2017 at 12:35 pm #14543
    Hari Prasaath K
    Participant

    Check whether the name given to the file (timers.h) and the header you used are with same spelling and have the header (timers.h) file and c file in the same folder. check with this and execute.

    April 9, 2017 at 7:19 am #14562
    Ashutosh Bhatt
    Participant

    you may have to include timer.h file in root directory

  • Author
    Posts
Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.
Log In

RSS Recent Posts

  • how to work on pcbs that are thick May 19, 2025
  • 100uF bypass Caps? May 19, 2025
  • Fuel Auto Shutoff May 18, 2025
  • Actin group needed for effective PCB software tutorials May 18, 2025
  • compatible eth ports for laptop May 18, 2025

Stay Up To Date

Newsletter Signup
EngineersGarage

Copyright © 2025 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy | Advertising | About Us

Search Engineers Garage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Advertise