logo elektroda
logo elektroda
X
logo elektroda
REKLAMA
REKLAMA
Adblock/uBlockOrigin/AdGuard mogą powodować znikanie niektórych postów z powodu nowej reguły.

[AVR][C] Naprawa biblioteki Lcd

mevelrik 17 Sty 2011 20:00 2166 6
REKLAMA
  • #1 9019628
    mevelrik
    Poziom 12  
    Mam pewien problem. Pobrałem z internetu bibliotekę do LCD HD44780, działa ładnie ale pod m.in. ATMega32 a pod ATMega8 nie kompiluje się. Postanowiłem ją poprawić i jak łatwo się domyśleć nadal nie działa ;/ Kompiluje się teraz ale nie nic nie wyświetla. Powiedzcie gdzie popełniłem błąd?

    Kod po zmianie:
    
    #include "delay.h"
    
    volatile uint16_t delayCount;
    
    void initializeDelayTimerMicrosecond(void)
    {
    	
    	TCCR1A = 0;
    	
    	TIFR |= _BV(OCF1A);
    	
    	TCCR1A = _BV(WGM11) | _BV(CS01);
    	
    	TCNT1L = 0;
    	
    	TIMSK |= _BV(OCIE1A);
    	
    	OCR1AL  = OCR_1MICROSECOND;
    }
    
    void initializeDelayTimerMillisecond(void)
    {
    	TCCR1A = 0;
    	
    	TIFR |= _BV(OCF1A);
    	
    	TCCR1A = _BV(WGM11) | _BV(CS02);
    	
    	TCNT1L = 0;
    	
    	TIMSK |= _BV(OCIE1A);
    	
    	OCR1AL  = OCR_1MILLISECOND;
    }
    
    
    void runDelay(uint16_t delayUnits)
    {
    	TCNT1L  = 0;
    	
    	delayCount = 0;
    	
    	while (delayCount != delayUnits)
    		;
    }
    
    void delay50us(uint16_t delayUnits)
    {
    	runDelay(delayUnits);
    }
    


    Kod przed zmianą:
    #include "delay.h"
    
    volatile uint16_t delayCount;
    
    void initializeDelayTimerMicrosecond(void)
    {
    	TCCR0 = 0;
    	
    	TIFR |= _BV(OCF0);
    	
    	TCCR0 = _BV(WGM01) | _BV(CS01);
    	
    	TCNT0 = 0;
    	
    	TIMSK |= _BV(OCIE0);
    	
    	OCR0  = OCR_1MICROSECOND;
    }
    
    void initializeDelayTimerMillisecond(void)
    {
    	TCCR0 = 0;
    	
    	TIFR |= _BV(OCF0);
    	
    	TCCR0 = _BV(WGM01) | _BV(CS02);
    	
    	TCNT0 = 0;
    	
    	TIMSK |= _BV(OCIE0);
    	
    	OCR0  = OCR_1MILLISECOND;
    }
    
    void runDelay(uint16_t delayUnits)
    {
    	TCNT0  = 0;
    	
    	delayCount = 0;
    	
    	while (delayCount != delayUnits)
    		;
    }
    
    void delay50us(uint16_t delayUnits)
    {
    	runDelay(delayUnits);
    }
    


    Błąd przy kompilacji oryginału:
    Build started 17.1.2011 at 18:38:02
    avr-gcc  -mmcu=atmega8 -Wall -gdwarf-2 -std=gnu99 -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -MD -MP -MT delay.o -MF dep/delay.o.d  -c  ../delay.c
    ../delay.c: In function 'initializeDelayTimerMicrosecond':
    ../delay.c:49: error: 'WGM01' undeclared (first use in this function)
    ../delay.c:49: error: (Each undeclared identifier is reported only once
    ../delay.c:49: error: for each function it appears in.)
    ../delay.c:56: error: 'OCIE0' undeclared (first use in this function)
    ../delay.c:60: error: 'OCR0' undeclared (first use in this function)
    ../delay.c: In function 'initializeDelayTimerMillisecond':
    ../delay.c:79: error: 'OCF0' undeclared (first use in this function)
    ../delay.c:84: error: 'WGM01' undeclared (first use in this function)
    ../delay.c:91: error: 'OCIE0' undeclared (first use in this function)
    ../delay.c:95: error: 'OCR0' undeclared (first use in this function)
    make: *** [delay.o] Error 1
    Build failed with 9 errors and 0 warnings...
    
  • REKLAMA
  • REKLAMA
  • #3 9019711
    mevelrik
    Poziom 12  
    Przepraszam nie dopisałem że to nie jest plik główny tylko delay.c, Pierwotna wersja kompilowała się i działała w symulacjach, moja wersja kompiluje się ale nie działa.

    Cytat:
    Nie trzeba niczego zmieniać w oryginale, ATmega8 ma te rejestry...
    więc z kąd błędy pojawiające się przy zmianie procesora?
  • REKLAMA
  • #4 9019723
    LordBlick
    VIP Zasłużony dla elektroda
    Ech, pośpieszyłem się, właśnie czytam notę katalogową... W Atmega8 możesz tylko na tym timerze korzystać z trybu Overflow (Wartość (0xFF-<Wartość dla OCR0>) należy wpisywać co przerwanie na jego początku). Dopiero nowsza wersja (Atmega88) ma tryb CTC.
    Na szybkiego to możesz przejść na Timer2 w trybie synchronicznym, ma zbliżone rejestry. Timer1 wymaga dodatkowych ustawień i kombinacji, więc nie polecam..
  • REKLAMA
  • #5 9019980
    mevelrik
    Poziom 12  
    Poprawiłem na timer2, kompiluje się, proteus też nie pokazuje błędów ale nic się nie wyświetla. Dobrze naniosłem poprawki przy zmianie z timera0 na timer2?

    /*
    **	Project:	Delay Functions
    **	Purpose:	Define a series of functions to delay for a specified
    **				time -- every millisecond or every ~50 microseconds.
    **
    **	Author:		Steven Pickles
    **	Date:		Saturday, July 02, 2005
    **
    **	Notes:		The timer delays were tested using an oscilloscope, but
    **				still are not 100% exact... although they are close.
    */
    
    
    /*
    **	Compiler Include Directives
    */
    #include "delay.h"
    
    
    /*
    **	Global Variables
    */
    
    volatile uint16_t delayCount;
    
    
    
    
    /*
    **	Function:		initializeDelayTimerMicrosecond
    **	Parameters:		<none>
    **	Purpose:		Initialize timer 0 to use the system clock and output
    **					compare 0 to generate an interrupt once per	microsecond.
    **					This is then used for any general purpose delay.
    **	Returns:		<none>
    */
    void initializeDelayTimerMicrosecond(void)
    {
    	//	Clear the timer/counter control register 0
    	TCCR2 = 0;
    	
    	//	Set the output compare match interrupt enable, and overflow
    	//	interrupt enable bits of the timer/counter interrupt flag register
    	TIFR |= _BV(OCF2);
    	
    	//	Set the waveform generation mode to accept register OCR0 as the
    	//	top value and clear the timer on a compare match (CTC) mode.  The
    	//	timer clock is equal to the system clock divided by 8.
    	TCCR2 = _BV(WGM21) | _BV(CS21);
    	
    	//	Clear the timer/counter register 0
    	TCNT2 = 0;
    	
    	//	Set the output compare flag, and overflow flag bits of the
    	//	timer/counter interrupt mask register
    	TIMSK |= _BV(OCIE2);
    	
    	//	Set the top value of the counter by setting the
    	//	OCR register to the predetermined value
    	OCR2  = OCR_1MICROSECOND;
    }
    
    
    /*
    **	Function:		initializeDelayTimerMillisecond
    **	Parameters:		<none>
    **	Purpose:		Initialize timer 0 to use the system clock and output
    **					compare 0 to generate an interrupt once per millisecond.
    **					This is then used for any general purpose delay.
    **	Returns:		<none>
    */
    void initializeDelayTimerMillisecond(void)
    {
    	//	Clear the timer/counter control register 0
    	TCCR2 = 0;
    	
    	//	Set the output compare match interrupt enable, and overflow
    	//	interrupt enable bits of the timer/counter interrupt flag register
    	TIFR |= _BV(OCF2);
    	
    	//	Set the waveform generation mode to accept register OCR0 as the
    	//	top value and clear the timer on a compare match (CTC) mode.  There
    	//	is a clock prescaler of 64 since the delay is 1 millisecond.
    	TCCR2 = _BV(WGM21) | _BV(CS22);
    	
    	//	Clear the timer/counter register 0
    	TCNT2 = 0;
    	
    	//	Set the output compare flag, and overflow flag bits of the
    	//	timer/counter interrupt mask register
    	TIMSK |= _BV(OCIE2);
    	
    	//	Set the top value of the counter by setting the
    	//	OCR register to the predetermined value
    	OCR2  = OCR_1MILLISECOND;
    }
    
    
    /*
    **	Function:		runDelay
    **	Parameters:		delayUnits - the number of times the interrupt must fire
    **								 in order for the delay to be complete
    **	Purpose:		Performs a delay for a specified number of units.
    **	Returns:		<none>
    */
    void runDelay(uint16_t delayUnits)
    {
    	//	Clear the timer/counter register 0
    	TCNT2  = 0;
    	
    	//	Clear the delay counter variable
    	delayCount = 0;
    	
    	//	Perform the delay with a simple loop until finished
    	while (delayCount != delayUnits)
    		;
    }
    
    
    /*
    **	Function:		delay50us
    **	Parameters:		delayUnits - the number of times the interrupt must fire
    **								 in order for the delay to be complete
    **	Purpose:		Performs a delay for a specified number of units.
    **					This is basically a wrapper function and is meant to be
    **					used as a wrapper for the actual delay function.
    **	Returns:		<none>
    */
    void delay50us(uint16_t delayUnits)
    {
    	//	Run the delay for delayUnits time
    	runDelay(delayUnits);
    }
    
  • #7 9020521
    mevelrik
    Poziom 12  
    Jestem jakiś chyba rozkojarzony (mam problemy z myśleniem). Oczywiście już działa. Poprawiłem w pliku głównym na:

    SIGNAL(SIG_OUTPUT_COMPARE2)


    Dzięki wielkie. Problem rozwiązany. Można zamykać :)[/code]
REKLAMA