avr-chat
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[avr-chat] POV code, works with breakpoints, problems without


From: Mikey Sklar
Subject: [avr-chat] POV code, works with breakpoints, problems without
Date: Sun, 6 Nov 2005 00:28:46 -0500
User-agent: Mutt/1.5.10i

I have a simple Persistence of Vision project that has been doing some
strange things this evening. When I set a breakpoint using avr-gdb, the
interrupts occur, and the correct "letters" are being sent to PORTB.
When I simple run the code via 'continue' command with no breakpoints
LED0 and LED6 are flashing and LED1-LED5 remaining solid with no change
at all which is totally unexpected behavior.

Included below is a description of my setup, build, and source.

ICE:            jtag-mkII
Programmer:     stk500
MCU:            ATmega32
avarice:        2.3-0cvs
avr-gcc:        4.0.2-1
avr-gdb:        6.3-0 
avr-libc:       1.2.5-1

$ avr-gcc -g -mmcu=atmega32 -Os -funsigned-char -funsigned-bitfields
  -fpack-struct -fshort-enums -Wall -Wstrict-prototypes
  -Wa,-ahlms=tiny_pov.lst  -Os -c tiny_pov.c

$ avr-gcc -g -mmcu=atmega32 -Os -funsigned-char -funsigned-bitfields
  -fpack-struct -fshort-enums -Wall -Wstrict-prototypes
  -Wa,-ahlms=tiny_pov.o  tiny_pov.o --output tiny_pov.elf
  -Wl,-Map=tiny_pov.map,--cref

$ avr-gcc -g -mmcu=atmega32 -Os -funsigned-char -funsigned-bitfields
  -fpack-struct -fshort-enums -Wall -Wstrict-prototypes
  -Wa,-ahlms=tiny_pov.elf  -o tiny_pov.out -Wl,-Map,tiny_pov.map tiny_pov.o

$ avr-objcopy -j .text -O ihex tiny_pov.out tiny_pov.hex

$ sudo avarice --erase --program --file tiny_pov.elf --mkII --jtag
  /dev/tty.USA19H4b12P1.1 --jtag-bitrate 250KHz :4242

$ avr-gdb tiny_pov.elf

/************************************************************
* Spell text on LEDs - POV (Persistence of Vision)          *  
*                                                           *  
* 20050920                                                  *  
* address@hidden                              *  
* address@hidden                                            *  
*                                                           *  
************************************************************/

#include <stdio.h>
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/signal.h>

#define TEXT_MAXLEN 17          /* MAX length of characters to display */
#define POV_CODE_MAXLEN 8       /* MAX length for each letter code */
#define WHITE_SPACE 0x00        /* Code for POV white space */
#define DELAY 200               /* standard delay */

int* letter_to_pov(char alpha); 
void blink_letter(int *ppovc);
SIGNAL(SIG_OVERFLOW0);

int main(void)
{

        /* 
         * Enable PORTB 0-6 as outputs
         */
        DDRB=0x7F;

        /* 
         * Counter setup 
         * prescalar 1/1024
         */
        TCCR0=(1<<CS00); 
        TCCR0=(1<<CS02);  

        /* 
         * start timer with nothing
         */
        TCNT0 = 0x00;

        /*
         * set lowest BIT of TIMSK to enable overflow interrupt
         */
        timer_enable_int(1<<TOIE0);

        /*
         * Set (global) Enable Interrupts
         */
        sei();

        while(1);
}


/* 
 * Timer0 Interrupt Service Routine
 * - 8bit
 * - rollover occurs at 255
 * - TCCR0 - Timer Counter Control Register
 * - 1024 divide ( CS00 = 1 / CS01 = 0 / CS02 = 1 )
 * - period 1 / 1024 (divider) 976us
 * - 976us * 205 = 200080us = ~200ms 
 * - requires reload of (256 - 205 ) 
 * - reload 51
 * - frequency 5Hz
 * - Flash letters at 5Hz
 */
SIGNAL(SIG_OVERFLOW0) {
        /* 
         * reload timer 51 dec or 0x33 hex
         */
        TCNT0 = 0x33; 

        /* 
         *  Blink this string 
         */
        char message[TEXT_MAXLEN] = "legalize science"; 
        char *p;

        /* 
         *  1. Loop through each letter of our message 
         *  2. obtain the POV code 
         *  3. print the letter to LEDs
         *  4. repeat 
         */
        for (p = message; *p; ++p) {
                blink_letter(letter_to_pov(*p));
        }
        p = message;
}


/* 
 *  Alphabetic representation in 7bit coordinates 
 *  Converts letter to blinking light format 
 *
 *  (example 'a' , 'b', 'c', and 'd' below)
 * 
 *    *****   ******   ******  *******
 *   *     *  *    *  *        *      *
 *   *     *  *   *  *         *      *
 *   *******  ****   *         *      *
 *   *     *  *   *  *         *      *
 *   *     *  *    *  *        *      *
 *   *     *  ******   ******  *******
 * 
 */ 
int* letter_to_pov(char alpha)
{
    static int space[] = {0x00};
    static int letters[][20] = {
        {0x3f,0x48,0x48,0x48,0x3f,0x00},           /* A */
        {0x7f,0x49,0x49,0x49,0x36,0x00},           /* B */
        {0x3e,0x41,0x41,0x41,0x22,0x00},           /* C */
        {0x7f,0x41,0x41,0x41,0x3e,0x00},           /* D */
        {0x7f,0x49,0x49,0x41,0x00},                /* E */
        {0x7f,0x48,0x48,0x40,0x00},                /* F */
        {0x3e,0x41,0x49,0x49,0x2e,0x00},           /* G */
        {0x7f,0x08,0x08,0x08,0x7f,0x00},           /* H */
        {0x7f,0x00},                               /* I */ 
        {0x02,0x01,0x01,0x7e,0x00},                /* J */
        {0x7f,0x08,0x18,0x24,0x43,0x00},           /* K */
        {0x7f,0x01,0x01,0x01,0x00},                /* L */
        {0x3f,0x40,0x40,0x3f,0x40,0x40,0x3f,0x00}, /* M */
        {0x7f,0x20,0x1C,0x02,0x7f,0x00},           /* N */        
        {0x3e,0x41,0x41,0x41,0x3e,0x00},           /* O */
        {0x3f,0x48,0x48,0x48,0x30,0x00},           /* P */
        {0x3e,0x41,0x45,0x43,0x3f,0x00},           /* Q */
        {0x7f,0x48,0x4c,0x4A,0x31,0x00},           /* R */
        {0x32,0x49,0x49,0x49,0x26,0x00},           /* S */
        {0x40,0x40,0x7F,0x40,0x40,0x00},           /* T */
        {0x3e,0x01,0x01,0x01,0x3e,0x00},           /* U */
        {0x78,0x06,0x01,0x06,0x78,0x00},           /* V */
        {0x7e,0x01,0x01,0x7e,0x01,0x01,0x7e,0x00}, /* W */
        {0x41,0x22,0x1c,0x22,0x41,0x00},           /* X */
        {0x40,0x20,0x1f,0x20,0x40,0x00},           /* Y */
        {0x43,0x45,0x49,0x51,0x61,0x00}            /* Z */
    };
    if (alpha == ' ') return space;
    else return letters[alpha - 'a'];
}

/* 
 * Loops through each letters set of hex codes displaying it to
 * PORTB 
 * example letter 'l' = 0x7f,0x01,0x01,0x01
 * each code will be displayed
 */

void blink_letter(int *ppovc) 
{
    int *p;
        /*
         *  Displays letter in several pieces across PORTB
         */ 
        for (p = ppovc; *p; ++p)
        {
                PORTB = *p; 
        } 
}




reply via email to

[Prev in Thread] Current Thread [Next in Thread]