This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CCS/TM4C123GH6PM: TIVA Library + TM4c123GXL launchboard+ CCS error with redefined timer.c

Part Number: TM4C123GH6PM


Tool/software: Code Composer Studio

Hello all.

I am sorry for my bad English.

I try to work with lcd on HD44780, and when i finished my program- i cant compilate it.

I dont know what's wrong. help please. all libraries are working. and no include errors.

#include <stdint.h>
#include <stdbool.h>
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "driverlib/sysctl.h"
#include "driverlib/gpio.h"
#include "driverlib/debug.h"
#include "driverlib/pwm.h"
#include "driverlib/pin_map.h"
#include "inc/hw_gpio.h"
#include "driverlib/rom.h"
#include "driverlib/timer.h"
#include "driverlib/timer.c"

    int timer1 (int i);
    int LCDINIT(int *timer);
    void LCDWIRE(int rs,int rw,int d7, int d6, int d5, int d4);


int main(void)
{
    SysCtlClockSet(SYSCTL_SYSDIV_1|SYSCTL_USE_OSC|SYSCTL_OSC_MAIN|SYSCTL_XTAL_16MHZ); // задали внешний кварц 16мгц и делитель 1
    SysCtlPWMClockSet(SYSCTL_PWMDIV_1); //задали делитель частоты для шим

    SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER1);// включили таймер.
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); //включили порт PA
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); //включили порт PB

    IntMasterDisable(); //Запрещаем процессору реагировать на прерывания, чтобы он не уходил в подпрограмму прерывания.

    GPIOPinTypeGPIOOutput(GPIO_PORTA_BASE,GPIO_PIN_2|GPIO_PIN_3|GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7); //настроили ножки порта PA2-7 на вывод
    GPIOPinTypeGPIOOutput(GPIO_PORTB_BASE,GPIO_PIN_4);

    TimerConfigure(TIMER1_BASE, TIMER_CFG_PERIODIC); // включаем таймер в режим полной ширины
    TimerLoadSet(TIMER1_BASE, TIMER_A, 160); //задаем период таймера 10мкс
    IntEnable(INT_TIMER1A); //разрешили прерывания по таймеру 1.
    TimerIntEnable(TIMER1_BASE,TIMER_TIMA_TIMEOUT); // разрешаем прерывание по переполнению таймера 1 (А т.к. используем 32 бит таймер)
    TimerEnable(TIMER1_BASE, TIMER_A); // включаем таймер

    timer1(1); //инициализировали програмный таймер

    int timer;
    while(1)
    {
        timer = timer1(2);
        LCDINIT(&timer);
        if (LCDINIT==1)
        {
            LCDWIRE(1,0,0,1,0,0);
            SysCtlDelay(100);
            LCDWIRE(1,0,0,1,0,0);
        }


    }

}
    int timer1 (int i)// таймер считает по 10мкс
    {
        static int long t;
        switch(i)
        {
        case 1:
        {
            t=0;
            break;
        }
        case 2:
        {
        if(TimerIntStatus(TIMER1_BASE,TIMER_TIMA_TIMEOUT)) // Проверяем флаг переполнения таймера
        {
            t+=1;
            TimerIntClear(TIMER1_BASE,TIMER_TIMA_TIMEOUT);//сбрасываем флаг прерывания
            return(t);
        }
        }
        }
    }
    void LCDWIRE(int rs,int rw,int d7, int d6, int d5, int d4)
    {
        if(rw==1)
             GPIOPinWrite(GPIO_PORTB_BASE,GPIO_PIN_4,0x1); //RW=1
            else
                GPIOPinWrite(GPIO_PORTB_BASE,GPIO_PIN_4,0x0); //RW=0
        if(rs==1)
             GPIOPinWrite(GPIO_PORTA_BASE,GPIO_PIN_2,0x1); //RS=1
            else
                GPIOPinWrite(GPIO_PORTA_BASE,GPIO_PIN_2,0x0); //RS=0
        if(d7==1)
            GPIOPinWrite(GPIO_PORTA_BASE,GPIO_PIN_7,GPIO_PIN_7); // данные d7
            else
                GPIOPinWrite(GPIO_PORTA_BASE,GPIO_PIN_7,0x0); // данные d7
        if(d6==1)
            GPIOPinWrite(GPIO_PORTA_BASE,GPIO_PIN_6,GPIO_PIN_6); // данные d6
            else
                GPIOPinWrite(GPIO_PORTA_BASE,GPIO_PIN_6,0x0); // данные d6
        if(d5==1)
            GPIOPinWrite(GPIO_PORTA_BASE,GPIO_PIN_5,GPIO_PIN_5); // данные d5
            else
                GPIOPinWrite(GPIO_PORTA_BASE,GPIO_PIN_5,0x0); // данные d5
        if(d4==1)
            GPIOPinWrite(GPIO_PORTA_BASE,GPIO_PIN_4,GPIO_PIN_4); // данные d4
            else
                GPIOPinWrite(GPIO_PORTA_BASE,GPIO_PIN_4,0x0); // данные d4
        GPIOPinWrite(GPIO_PORTA_BASE,GPIO_PIN_3,0x1); //E=1 строб
        SysCtlDelay(50);
        GPIOPinWrite(GPIO_PORTA_BASE, GPIO_PIN_3, 0x0); //E=1 строб
    }
    int LCDINIT (int *timer)
    {
        static int SW;

        switch(SW)
        {
        case 0:
        {
            if(*timer>4000)//задержка 40мс
            {
                SW=1;
                *timer=0;
            }
            break;
        }
        case 1: //инициализация таймера  case 1-
        {
            LCDWIRE(0,0,0,0,1,1);
            SW=2;
            *timer=0;
            break;
        }
        case 2:
        {
            if(*timer>410)// задержка 4.1мс
            {
                LCDWIRE(0,0,0,0,1,1);
                SW=3;
                *timer=0;
            }
            break;
        }
        case 3:
        {
            if(*timer>=10)// задержка 100мкс
            {
                LCDWIRE(0,0,0,0,1,1);
                SW=4;
                *timer=0;
            }
            break;
        }
        case 4:
        {
            if(*timer>=1)// задержка 10мкс
           {
                LCDWIRE(0,0,0,0,1,0);
                SW=5;
                *timer=0;
           }
           break;
        }
        case 5:
        {
            if(*timer>=1)// задержка 10мкс
           {
                LCDWIRE(0,0,0,0,1,0);
                SW=6;
                *timer=0;
           }
           break;
        }
        case 6:
        {
            if(*timer>=1)// задержка 10мкс
           {
                LCDWIRE(0,0,1,0,0,0);
                SW=7;
                *timer=0;
           }
           break;
        }
        case 7:
        {
            if(*timer>=1)// задержка 10мкс
           {
                LCDWIRE(0,0,0,0,0,0);
                SW=8;
                *timer=0;
           }
           break;
        }
        case 8:
        {
            if(*timer>=1)// задержка 10мкс
           {
                LCDWIRE(0,0,1,0,0,0);
                SW=9;
                *timer=0;
           }
           break;
        }
        case 9:
        {
            if(*timer>=1)// задержка 10мкс
           {
                LCDWIRE(0,0,0,0,0,0);
                SW=10;
                *timer=0;
           }
           break;
        }
        case 10:
        {
            if(*timer>=1)// задержка 10мкс
           {
                LCDWIRE(0,0,0,0,0,1);
                SW=11;
                *timer=0;
           }
           break;
        }
        case 11:
        {
            if(*timer>=1)// задержка 10мкс
           {
                LCDWIRE(0,0,0,0,0,0);
                SW=12;
                *timer=0;
           }
           break;
        }
        case 12:
        {
            if(*timer>=1)// задержка 10мкс
           {
                LCDWIRE(0,0,0,1,1,0);
                SW=13;
                *timer=0;
           }
           break;
        }
        case 13:
        {
            return(1);
        }
    }
    }

Thanks for help.

  • Hi,

     What do you mean you cannot compile? What is the error message you get during compile?

     I tried to compile your code and below is what I got.

    If I click OK and eventually the program will compile for me. I'm not sure if the error I'm getting is the same as yours. Can you try to remove these non-English characters in your comments and try again?

  • Hi!!

    i try to delete all comments. no changes.

    here my errors.

    i don't know why problem with linking because last my project with timer and pwm works.

    i think problem in driverlib/timer.c , but don't know any solution.

  • Alexander Zharichev said:
    #include "driverlib/timer.h"
    #include "driverlib/timer.c"

    While it is possible this is correct, it is unlikely.

    You do not usually include the source code for a library in your own source. I've only seen that done with badly written libraries (and that many years ago) and some sort of "C" compilers*.

    Robert

    * That claim greater efficiency by breaking the language

  • Poster Robert has well identified the "improper" inclusion of the .c file - never good!     (not even w/in the Z-World dayze...)

    Beyond this - the Lcd code you present is near - if not - the (pardon) "worst I've ever seen!"     

    There is a very "MIXED" understanding of  "Setting a GPIO pin" and there appears "No understanding of doing a "complete Port Write!"       Which would immensely simplify & reduce your code's bulk.

    Here's key detail:   "Setting GPIO pin:"

    GPIOPinWrite(GPIO_PORTB_BASE,GPIO_PIN_4, 0x1); // RW=1  This will fail!
                else
                    GPIOPinWrite(GPIO_PORTB_BASE,GPIO_PIN_4,0x0); //RW=0
            if(rs==1)
                 GPIOPinWrite(GPIO_PORTA_BASE,GPIO_PIN_2, 0x1); // RS=1  This will fail!
                else
                    GPIOPinWrite(GPIO_PORTA_BASE,GPIO_PIN_2,0x0); //RS=0

    You cannot set any GPIO pin  (but for GPIO_PIN_0) by employing the "normal" "0x1!"      I show just 2 examples of that here - yet it occurs  throughout your code.    In each case (above) both RS & RW will remain "0!"

    Yet - a few lines later - you (or the code writer) magically "understand & correct"  this "Set an individual GPIO pin" task.      (How is that?)

    GPIOPinWrite(GPIO_PORTA_BASE,GPIO_PIN_7, GPIO_PIN_7); // данные d7    this will Set bit 7
                else
                    GPIOPinWrite(GPIO_PORTA_BASE,GPIO_PIN_7,0x0); // данные d7
            if(d6==1)
                GPIOPinWrite(GPIO_PORTA_BASE,GPIO_PIN_6, GPIO_PIN_6); // данные d6    this will Set bit 6
                else
                    GPIOPinWrite(GPIO_PORTA_BASE,GPIO_PIN_6,0x0); // данные d6

    It is noted that you employ, "4 bit LCD code/operation" - which is NEVER recommended for beginners - and even for experts - proves vulnerable to noise bursts - which may "throw the nibble sequence OFF" yielding (only) garbled Lcd screens.     That's a BIG price to pay at the cost of 4 GPIOs - too big - myself/others would say!

    Your use of the MCU's Timer - to create just a few delays - appears "overkill" and a mistake in such delay (too short) will render the Lcd inoperable!     KISS directs you to use the far simpler, "SysCtlDelay()" function - setting it uniquely - as required by HD44780.      (A forum search will reveal that I've placed that aspect of the spec "right here" - for the ease of others...)

    The initialization of such screens is of great importance - and the code presented is "Unlikely to satisfy the HD44780's demands" - while "frying the brains" (really - a 13 step "switch") of any/all "would be" helpers...