NerdKits - electronics education for a digital generation

You are not logged in. [log in]

NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.

Microcontroller Programming » Code Doctor needed.

March 17, 2012
by Farmerjoecoledge
Farmerjoecoledge's Avatar

I lost the original code so I put the two back together and she compiles but only the display works, the heart code is broken. When heart.c is compiled by itself it works fine.

// forumlcdscroll.c // atmega168

define F_CPU 14745600

include <stdio.h>

include <stdlib.h>

include <avr/io.h>

include <avr/interrupt.h>

include <avr/pgmspace.h>

include <inttypes.h>

include "../libnerdkits/delay.h"

include "../libnerdkits/uart.h"

include "../libnerdkits/lcd.h"

// PIN DEFINITIONS: // // PC4 -- LED anode

// PIN DEFINITIONS: // // PC5 ROW DRIVER // PB1-PB5, PC0-PC4 : Column drivers 0 - 10 // We will use one row, and 10 column drivers. Switching the // direction of every other LED, this allows us to drive 20 LEDs

define ROWS 1

define COLS 20

volatile uint8_t la_row; volatile uint8_t duty[COLS]; //keeps the duty cycle of every LED: 0 - never on, 64 - all on volatile uint8_t incrementor;

//duty 0 - 64 void set_duty(uint8_t j, uint8_t the_duty) { if(j < COLS){ duty[j] = (the_duty > 64) ? 64 : the_duty; }
}

//set all the LEDs to full duty void full_duty(){ uint8_t j; for(j=0;j<COLS;j++){ duty[j] = 64; } }

//retrieve duty inline uint8_t duty_get(uint8_t j) { if(j < COLS) { return duty[j]; } else { return 0; } }

//shortcut to set duty full on or full off inline void ledarray_set(uint8_t j, uint8_t onoff) { if(j < COLS) { if(onoff) { duty[j] = 64; } else { duty[j] = 0; } } }

inline void ledarray_set_columndriver(uint8_t j, uint8_t onoff, uint8_t sense) { // cols 0-4: PB1-5 // cols 5-9: PC0-4 if(j < 5) { if(onoff) { PORTB |= (1 << (PB1 + j)); } else { PORTB &= ~(1<< (PB1 + j)); } if(sense == onoff) { DDRB |= (1 << (PB1 + j)); } else { DDRB &= ~(1 << (PB1 + j)); PORTB &= ~(1 << (PB1 + j)); } } else { if(onoff) { PORTC |= (1 << (PC0 + (j-5))); } else { PORTC &= ~(1<< (PC0 + (j-5))); }
if(sense == onoff) { DDRC |= (1 << (PC0 + (j-5))); } else { DDRC &= ~(1 << (PC0 + (j-5))); PORTC &= ~(1 << (PC0 + (j-5))); } } }

inline void ledarray_all_off() { // turn off all row drivers DDRC &= ~(1<<PC5); PORTC &= ~(1<<PC5);

// turn off all column drivers DDRC &= ~( (1<<PC0) | (1<<PC1) | (1<<PC2) | (1<<PC3) | (1<<PC4) ); PORTC &= ~( (1<<PC0) | (1<<PC1) | (1<<PC2) | (1<<PC3) | (1<<PC4) ); DDRB &= ~( (1<<PB1) | (1<<PB2) | (1<<PB3) | (1<<PB4) | (1<<PB5) ); PORTB &= ~( (1<<PB1) | (1<<PB2) | (1<<PB3) | (1<<PB4) | (1<<PB5) ); }

SIGNAL(SIG_OVERFLOW0) {

//keep a counter to provide duty cycle incrementor++; if(incrementor == 64) incrementor = 0;

// turn off old row driver ledarray_all_off();

// increment row number if(++la_row == 2*ROWS) la_row = 0;

// set column drivers appropriately uint8_t j; if(la_row%2 == 0) { // even la_row number: fill even columns for(j=0; j<COLS/2; j++) { //check duty for each LED, do not turn on if duty is less than incrementor if(duty[2*j] > incrementor) ledarray_set_columndriver(j, 1, 1); else ledarray_set_columndriver(j, 0, 1); } // activate row driver SINK PORTC &= ~(1 << (PC5)); DDRC |= (1 << (PC5)); } else { // odd la_row number: fill odd columns for(j=0; j<COLS/2; j++) { //check duty for each LED, do not turn on if duty is less than incrementor if(duty[2*j + 1] > incrementor) ledarray_set_columndriver(j, 0, 0); else ledarray_set_columndriver(j, 1, 0); } // activate row driver SOURCE PORTC |= (1 << (PC5)); DDRC |= (1 << (PC5)); } }

void ledarray_init() { incrementor = 0;

// Timer0 CK/8 (7000Hz) TCCR0B = (1<<CS01) | (0<<CS00); TIMSK0 = (1<<TOIE0);

// outputs (set row drivers high for off) DDRC &= ~( (1<<PC0) | (1<<PC1) | (1<<PC2) | (1<<PC3) | (1<<PC4) | (1<<PC5) ); DDRB &= ~( (1<<PB1)|(1<<PB2)|(1<<PB3)|(1<<PB4)|(1<<PB5) ); }

void ledarray_blank() { uint8_t j; for(j=0; j<COLS; j++) { ledarray_set(j,0); } }

//turn on all LEDs void all(){ uint8_t j; for(j=0; j<COLS; j++) { ledarray_set(j,1); } }

//blink all LEDs slowly void blink_all(uint16_t delay, uint8_t times){

uint8_t i,j,z; for(i=0;i<times;i++){

for(j=0;j<40;j++){ //light up
  for(z=0; z<COLS; z++) {
    duty[z] = j;
  }
  delay_ms(delay);
}

for(j=40;j>2;j--){ //dim out
  for(z=0; z<COLS; z++) {
    duty[z] = j;
  }
  delay_ms(delay);
}

} }

void set_all_duty(uint8_t set){ uint8_t i; for(i=0;i<COLS;i++){ duty[i] = set; }

}

//random twinking effect void twinkle(){ FILE uart_stream = FDEV_SETUP_STREAM(uart_putchar, uart_getchar, _FDEV_SETUP_RW);

//set all LEDs to small brightness set_all_duty(2);

//one tenth of the max rand() will return int limit = RAND_MAX/10;

//keep the current state of each LED //0 - off //1 - brightening //2 - dimming uint8_t state[COLS]; uint8_t max_bright[COLS]; uint8_t a; for(a=0; a<COLS; a++) { state[a] = 0; max_bright[a] = 0; }

uint8_t run = 0; uint32_t brightCalc; while(1){

 if(run == COLS) 
run = 0;

 //lightIt will be 1, 1 in 10 times
 uint16_t rand = abs(random());
 uint8_t lightIt = (rand < limit) ? 1 : 0;

 //chanche state off one LED to 1, if lightIt is on.
 //1 in 10 LEDs will begin a twinkle every time the the whie loop goes around
 if(((lightIt == 1) && (state[run] == 0))){
   state[run] = 1;
   brightCalc = (((uint32_t)rand * 32) / limit ) ;
   max_bright[run] = (uint8_t)brightCalc + 10;
      //fprintf_P(&uart_stream, PSTR("max %d, rand %d, bright %d \n\r"),RAND_MAX,rand,brightCalc);  
 }

 uint8_t i;
 for(i=0; i<COLS; i++) {
    //increment duty of all LEDs in state 1 by 1 (make it brighter)
    if(state[i] == 1){
  duty[i] = duty[i] + 1;
      //switch to state 2 once we reach max brightness
  if(duty[i] == max_bright[i]){
    state[i] = 2;
  }
     //decrement duty of all LEDs in state 2
    } else if(state[i] == 2) {
   duty[i] = duty[i] - 1;
       //return to state 0 once we reach bottom of brightness
       if(duty[i] == 2) 
    state[i] = 0;
    }
 }

 delay_ms(15);
 run++;

}

}

int main() { // LED as output DDRC |= (1<<PC4);

// turn on LED PORTC |= (1<<PC4);

// fire up the LCD lcd_init(); lcd_home();

// Variable to hold our current scroll offset. int8_t scrollPos=0;

// Variable to iterate through the 20-wide LCD screen. uint8_t i;

// print message to screen // 20 columns wide: lcd_line_one(); lcd_write_string(PSTR(" <THE WHALE TAIL> "));

// This is our actual string, longer than the LCD width, // stored in program memory (flash). const char *linetwo = PSTR(">>>THE WHALE TAIL>>REPRESENTS EXPERIENCE-STRENGTH-WISDOM-AND-STAMINA..THE WHALE TAIL IS ALSO LINKED TO TRAVEL COMPANIONSHIP AND THE LOVE OF NATURE >>THE WHALE IS THE LARGEST MAMMAL ON EARTH...WITH THE LARGEST BRAIN >>> ");

// This calculates its width once
// (For the string above, linetwolen = 200)
uint8_t linetwolen = strlen_P(linetwo);

// Main loop
while(1) {
// Move to the 2nd line of the LCD.
lcd_line_two();

for(i=0; i<20; i++) {
// For each of the 20 columns of the LCD display,
// we want to write a particular character from the // string to be scrolled.
// Specifically, for column i (0..19), we want to write // the (scrollPos+i) character of the string as we shift it around.
// But we take (scrollPos+i) MOD linetwolen to allow us to // "wrap around". // Calculate the right character number ((scrollPos+i)%linetwolen) // and add this to the linetwo variable, essentially moving forward // in memory by that many bytes. // Then read it from program memory (pgm_read_byte). // Finally, write it out to the LCD (lcd_write_data). lcd_write_data(pgm_read_byte(linetwo + ((scrollPos+i)%linetwolen)));
}

// Shift to the left by one position. When we get to having
// shifted by the entire length fo the string, then reset back to zero.
scrollPos = (scrollPos + 1) % linetwolen;

// Delay about 3/8s of a second before re-displaying.
delay_ms(333);

// print message to screen // 20 columns wide: // 01234567890123456789

lcd_line_three(); lcd_write_string(PSTR("THE LARGEST MAMMAL ")); lcd_line_four(); lcd_write_string(PSTR(" THE LARGEST BRAIN"));

// turn off that LED PORTC &= ~(1<<PC4); }

}

Also, the last two lines above show up in the scroll, and the random jibberish is still there, in the scroll towards the end. fjc

March 18, 2012
by Farmerjoecoledge
Farmerjoecoledge's Avatar

Come on guys, this is easy stuff.

If the code didn't compile I would be debugging it myself, but when it compiled first time I thought AMAZING, now here I sit. The only thing I can think of is the program is too big.

March 19, 2012
by Rick_S
Rick_S's Avatar

Grant,

1st, try to re-post it to the forum but this time after you've pasted it, select all you pasted and press the button below preview button that says "Indent Selection as Code Block". That will format it so we can read it. Then preview it. If it still looks all jumbled up like it is above, try again until it comes out right.

Not trying to be rude, but it's hard to even follow the piled up mish/mash above.

Rick

March 19, 2012
by Farmerjoecoledge
Farmerjoecoledge's Avatar

Thanks there Rick,

I put the four > before pasteing, it looked big on the preview, but it was the same, basiclly. Another thing I've never done successfully on this forum.

I'm going back into retirement. I just compiled the heart.c with lcdscroll.c and the compiler went right by the heart code and compiled just the lcdscroll. I had compiled the heart.c by itself just previous. Not to worry, just can't take it like the good ole days.

I'll lurk around for awhile, but it's off to the ballgame.

March 20, 2012
by Farmerjoecoledge
Farmerjoecoledge's Avatar

Someone like to give this a shot? This is the scroll for the 4x20 lcd.

The heart code can be found on the tutorials page.

Is this another 'just me' things? or can you compile the two?

Total program size 15.3 kib, memory is 16.000. Flashes only 9,460, the size of the scroll code.

// forumlcdscroll.c
    // atmega168

    #define F_CPU 14745600

    #include <stdio.h>

    #include <avr/io.h>
    #include <avr/interrupt.h>
    #include <avr/pgmspace.h>
    #include <inttypes.h>

    #include "../libnerdkits/delay.h"
    #include "../libnerdkits/lcd.h"

    // PIN DEFINITIONS:
    //
    // PC4 -- LED anode

    int main() {
      // LED as output
      DDRC |= (1<<PC4);

      // turn on LED
      PORTC |= (1<<PC4);

      // fire up the LCD
      lcd_init();
      lcd_home();

      // Variable to hold our current scroll offset.
      int8_t scrollPos=0;

      // Variable to iterate through the 20-wide LCD screen.
      uint8_t i;

      // print message to screen
      //             20 columns wide:
      lcd_line_one();
      lcd_write_string(PSTR("  <THE WHALE TAIL>  "));

      // This is our actual string, longer than the LCD width,
      // stored in program memory (flash).
      const char *linetwo = PSTR(">>>ENTER YOUR TEXT HERE >><< NOT NESSESARY <<< MINE HAS RANDOM TEXT 144 CELLS DOWN THIS LINE ");

      // This calculates its width once                                                                                                                                                                                                                                                       
      // (For the string above, linetwolen = 200)                                                                                                                                                                                                                                     
      uint8_t linetwolen = strlen_P(linetwo);

      // Main loop                                                                                                                                                                                                                                                                            
      while(1)  {                                                                                                                                                                                                                                                                             
      // Move to the 2nd line of the LCD.                                                                                                                                                                                                                                              
      lcd_line_two();

      for(i=0; i<20; i++)  {                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            
      // For each of the 20 columns of the LCD display,                                                                                                                                                                                                                                                  
      // we want to write a particular character from the 
      // string to be scrolled.                                                                                                                                                                                                                                                         
      // Specifically, for column i (0..19), we want to write 
      // the (scrollPos+i) character of the string as we shift it around.                                                                                                                                                                                                                           
      // But we take (scrollPos+i) MOD linetwolen to allow us to 
      // "wrap around".
      // Calculate the right character number ((scrollPos+i)%linetwolen)
      // and add this to the linetwo variable, essentially moving forward
      // in memory by that many bytes.
      // Then read it from program memory (pgm_read_byte).
      // Finally, write it out to the LCD (lcd_write_data).
      lcd_write_data(pgm_read_byte(linetwo + ((scrollPos+i)%linetwolen)));                                                                                                                                                                                                                                                        
        }

      // Shift to the left by one position.  When we get to having                                                                                                                                                                                                                                        
      // shifted by the entire length fo the string, then reset back to zero.                                                                                                                                                                                                                       
      scrollPos = (scrollPos + 1) % linetwolen;

      // Delay about 3/8s of a second before re-displaying.                                                                                                                                                                                                                                                    
      delay_ms(333);

      // print message to screen
      //             20 columns wide:
      //                     01234567890123456789

      lcd_line_three();
      lcd_write_string(PSTR("THE LARGEST MAMMAL  "));
      lcd_line_four();
      lcd_write_string(PSTR("   THE LARGEST BRAIN"));

       // turn off that LED
      PORTC &= ~(1<<PC4);
      }

    }

>>>>

// ledheart.c
// for NerdKits with ATmega168
// hevans@nerdkits.com
// modified from ledarray.c

#define F_CPU 14745600

#include <stdio.h>
#include <stdlib.h>

#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/pgmspace.h>
#include <inttypes.h>

#include "../libnerdkits/delay.h"
#include "../libnerdkits/uart.h"
#include "../libnerdkits/lcd.h"

// PIN DEFINITIONS:
//
// PC5 ROW DRIVER
// PB1-PB5, PC0-PC4 : Column drivers 0 - 10
// We will use one row, and 10 column drivers. Switching the 
// direction of every other LED, this allows us to drive 20 LEDs
#define ROWS 1
#define COLS 20

volatile uint8_t la_row;
volatile uint8_t duty[COLS]; //keeps the duty cycle of every LED: 0 - never on, 64 - all on
volatile uint8_t incrementor;

//duty 0 - 64
void set_duty(uint8_t j, uint8_t the_duty) {
  if(j < COLS){
    duty[j] = (the_duty >  64) ? 64 : the_duty;
  }  
}

//set all the LEDs to full duty
void full_duty(){
  uint8_t j;
  for(j=0;j<COLS;j++){
    duty[j] = 64;
  }
}

//retrieve duty
inline uint8_t duty_get(uint8_t j) {
  if(j < COLS) {
    return duty[j];
  } else {
    return 0;
  }
}

//shortcut to set duty full on or full off
inline void ledarray_set(uint8_t j, uint8_t onoff) {
  if(j < COLS) {
    if(onoff) {
      duty[j] = 64;
    } else {
      duty[j] = 0;
    }
  }
}

inline void ledarray_set_columndriver(uint8_t j, uint8_t onoff, uint8_t sense) {
  // cols 0-4: PB1-5
  // cols 5-9: PC0-4
  if(j < 5) {
    if(onoff) {
      PORTB |= (1 << (PB1 + j));
    } else {
      PORTB &= ~(1<< (PB1 + j));
    }
    if(sense == onoff) {
      DDRB |= (1 << (PB1 + j));
    } else {
      DDRB &= ~(1 << (PB1 + j));
      PORTB &= ~(1 << (PB1 + j));
    }
  } else {
    if(onoff) {
      PORTC |= (1 << (PC0 + (j-5)));
    } else {
      PORTC &= ~(1<< (PC0 + (j-5)));
    }  
    if(sense == onoff) {
      DDRC |= (1 << (PC0 + (j-5)));
    } else {
      DDRC &= ~(1 << (PC0 + (j-5)));
      PORTC &= ~(1 << (PC0 + (j-5)));
    }
  }
}

inline void ledarray_all_off() {
  // turn off all row drivers
  DDRC &= ~(1<<PC5);
  PORTC &= ~(1<<PC5);

  // turn off all column drivers
  DDRC &= ~( (1<<PC0) | (1<<PC1) | (1<<PC2) | (1<<PC3) | (1<<PC4) );
  PORTC &= ~( (1<<PC0) | (1<<PC1) | (1<<PC2) | (1<<PC3) | (1<<PC4) );
  DDRB &= ~( (1<<PB1) | (1<<PB2) | (1<<PB3) | (1<<PB4) | (1<<PB5) );
  PORTB &= ~( (1<<PB1) | (1<<PB2) | (1<<PB3) | (1<<PB4) | (1<<PB5) );
}

SIGNAL(SIG_OVERFLOW0) {

  //keep a counter to provide duty cycle
  incrementor++;
  if(incrementor == 64) 
    incrementor = 0;

  // turn off old row driver
  ledarray_all_off();

  // increment row number
  if(++la_row == 2*ROWS)
    la_row = 0;

  // set column drivers appropriately
  uint8_t j;
  if(la_row%2 == 0) {
    // even la_row number: fill even columns
    for(j=0; j<COLS/2; j++) {
      //check duty for each LED, do not turn on if duty is less than incrementor
      if(duty[2*j] > incrementor)
        ledarray_set_columndriver(j, 1, 1);
      else
        ledarray_set_columndriver(j, 0, 1);
    }
    // activate row driver SINK
    PORTC &= ~(1 << (PC5));
    DDRC |= (1 << (PC5));
  } else {
    // odd la_row number: fill odd columns
    for(j=0; j<COLS/2; j++) {
      //check duty for each LED, do not turn on if duty is less than incrementor
      if(duty[2*j + 1] > incrementor)
        ledarray_set_columndriver(j, 0, 0);
      else
        ledarray_set_columndriver(j, 1, 0);
    }
    // activate row driver SOURCE
    PORTC |= (1 << (PC5));
    DDRC |= (1 << (PC5));
  }
}

void ledarray_init() {
  incrementor = 0;

  // Timer0 CK/8 (7000Hz)
  TCCR0B = (1<<CS01) | (0<<CS00);
  TIMSK0 = (1<<TOIE0);

  // outputs (set row drivers high for off)
  DDRC &= ~( (1<<PC0) | (1<<PC1) | (1<<PC2) | (1<<PC3) | (1<<PC4) | (1<<PC5) );
  DDRB &= ~( (1<<PB1)|(1<<PB2)|(1<<PB3)|(1<<PB4)|(1<<PB5) );
}

void ledarray_blank() {
    uint8_t j;
    for(j=0; j<COLS; j++) {
      ledarray_set(j,0);
    }
}

//turn on all LEDs
void all(){
  uint8_t j;
    for(j=0; j<COLS; j++) {
      ledarray_set(j,1);
    }
}

//blink all LEDs slowly
void blink_all(uint16_t delay, uint8_t times){

  uint8_t i,j,z;
  for(i=0;i<times;i++){

    for(j=0;j<40;j++){ //light up
      for(z=0; z<COLS; z++) {
        duty[z] = j;
      }
      delay_ms(delay);
    }

    for(j=40;j>2;j--){ //dim out
      for(z=0; z<COLS; z++) {
        duty[z] = j;
      }
      delay_ms(delay);
    }

  }
}

void set_all_duty(uint8_t set){
  uint8_t i;
  for(i=0;i<COLS;i++){
    duty[i] = set;
  }

}

//random twinking effect
void twinkle(){
   FILE uart_stream = FDEV_SETUP_STREAM(uart_putchar, uart_getchar, _FDEV_SETUP_RW);

   //set all LEDs to small brightness
   set_all_duty(2);

   //one tenth of the max rand() will return
   int limit = RAND_MAX/10;

   //keep the current state of each LED 
   //0 - off
   //1 - brightening
   //2 - dimming
   uint8_t state[COLS];
   uint8_t max_bright[COLS];
   uint8_t a;
   for(a=0; a<COLS; a++) {
      state[a] = 0;
      max_bright[a] = 0;
   }

   uint8_t run = 0;
   uint32_t brightCalc;
   while(1){

     if(run == COLS) 
    run = 0;

     //lightIt will be 1, 1 in 10 times
     uint16_t rand = abs(random());
     uint8_t lightIt = (rand < limit) ? 1 : 0;

     //chanche state off one LED to 1, if lightIt is on.
     //1 in 10 LEDs will begin a twinkle every time the the whie loop goes around
     if(((lightIt == 1) && (state[run] == 0))){
       state[run] = 1;
       brightCalc = (((uint32_t)rand * 32) / limit ) ;
       max_bright[run] = (uint8_t)brightCalc + 10;
          //fprintf_P(&uart_stream, PSTR("max %d, rand %d, bright %d \n\r"),RAND_MAX,rand,brightCalc);  
     }

     uint8_t i;
     for(i=0; i<COLS; i++) {
        //increment duty of all LEDs in state 1 by 1 (make it brighter)
        if(state[i] == 1){
      duty[i] = duty[i] + 1;
          //switch to state 2 once we reach max brightness
      if(duty[i] == max_bright[i]){
        state[i] = 2;
      }
         //decrement duty of all LEDs in state 2
        } else if(state[i] == 2) {
       duty[i] = duty[i] - 1;
           //return to state 0 once we reach bottom of brightness
           if(duty[i] == 2) 
        state[i] = 0;
        }
     }

     delay_ms(15);
     run++;

   }

}

int main() {
  FILE lcd_stream = FDEV_SETUP_STREAM(lcd_putchar, 0, _FDEV_SETUP_WRITE);

  ledarray_init();
  lcd_init();

  lcd_home();                //012345678901234567890123  
  fprintf_P(&lcd_stream, PSTR("  Happy Valentines Day  "));
  lcd_line_two();
  fprintf_P(&lcd_stream, PSTR("     From NerdKits      "));  
  // activate interrupts
  sei();

  // init serial port
  uart_init();
  FILE uart_stream = FDEV_SETUP_STREAM(uart_putchar, uart_getchar, _FDEV_SETUP_RW);
  stdin = stdout = &uart_stream;

  //blink_all(10,10);
  //ledarray_blank();
  twinkle();
  return 0;
}
March 20, 2012
by pcbolt
pcbolt's Avatar

Joebits -

If you're worried about using up code space, it looks like you can get rid of all the "fprintf" functions. You can eliminate lines 307, 373, 386-388, and re-write lines 379 and 381 to use "lcd_write_string". Then just get rid of the line in your "makefile" that includes the references to "vprintf". You may have to include "math.h" somewhere, I'm not sure. This should free up about 6.5K

March 20, 2012
by Farmerjoecoledge
Farmerjoecoledge's Avatar

Thanks for the tips there pcbolt but I'm sure it wouldn't compile if it was too big, so I really don't think that's the problem. I need someone to put it together and compile it to see if my compiler is screwed again.

Like it goes right by the heart code and just compiles the scroll.

Both of these pieces of code compile by themselves.

March 20, 2012
by pcbolt
pcbolt's Avatar

Farmer Joe -

I guess I'm confused about one thing. It looks like you're trying to compile two separate source code files into one program. Neither of the programs calls a function from the other and there are two "main()" routines which I'm pretty sure won't do. Also, both of the "while(1)" loops don't exit so one will always get run and the other will never get run. Can you post the "makefile" that you used?

March 20, 2012
by Ralphxyz
Ralphxyz's Avatar

So how do you compile two separate .C programs together?

Can one "include" the .hex of one?

Ralph

March 21, 2012
by Farmerjoecoledge
Farmerjoecoledge's Avatar

Thanks for the interest guys, pcbolt, I had these two pieces of code together and running on my Whale Tail in 2010. You tell me, a year and a half later and that code disappeared. Now making it again.

So yeah, the heart code already has the lcd function in it but doesn't scroll and it's for the 2x24 old lcd. I just lopped off the old lcd code and added lcdscoll.c from int: on. (top piece of code).

The make file is the original initialload makefile, I use to edit the makefile but now I just copy it to another folder and just change the name of the .c file to initialload.

So it sounds like I got some extra stuff in the code, but why no errors?

March 21, 2012
by pcbolt
pcbolt's Avatar

Joe -

As to "why no errors?", your guess is as good as mine. It's possible the compiler was able to resolve all the open parenthesis, brackets, outside dependencies etc, when it got to the end of the main() routine that it just said "OK I'm done... all is good". But I think I may have a fix to your problem. On your last code posting, at line 371 it reads:

delay_ms(15);
run++;

Right after that add:

scroll_time++;
if (scroll_time > 20){
    scroll_time = 0;
    lcd_line_two();
    for(i=0; i<20; i++)  {
        lcd_write_data(pgm_read_byte(linetwo + ((scrollPos+i)%linetwolen)));
    }
    scrollPos = (scrollPos + 1) % linetwolen;
}

At line 385 get rid of the three lines after "lcd_home()" and replace with:

int8_t scrollPos=0;
uint8_t i;
lcd_line_one();
lcd_write_string(PSTR("  <THE WHALE TAIL>  "));
const char *linetwo = PSTR(">>>ENTER YOUR TEXT HERE >><< NOT NESSESARY <<< MINE    HAS RANDOM TEXT 144 CELLS DOWN THIS LINE ");
uint8_t linetwolen = strlen_P(linetwo);
lcd_line_three();
lcd_write_string(PSTR("THE LARGEST MAMMAL  "));
lcd_line_four();
lcd_write_string(PSTR("   THE LARGEST BRAIN"));

uint8_t scroll_time = 0;

Then just get rid of everything above line 95. Hope it works.

March 24, 2012
by Farmerjoecoledge
Farmerjoecoledge's Avatar

I shouldn't have asked. You want errors I got errors, starting at the very first imput of new stuff. Well that was the easy way now I guess I got a good three year project. :|

March 24, 2012
by pcbolt
pcbolt's Avatar

Sorry about that Joe, I gave you a bum steer on that -

I got the variables "scoped" all wrong. All the stuff in the last block of code I posted won't work the way it is inside the function "twinkle()", only in "main()". I think it can be salvaged easy enough.

Move all this:

int8_t scrollPos=0;
uint8_t i;
lcd_line_one();
lcd_write_string(PSTR("  <THE WHALE TAIL>  "));
const char *linetwo = PSTR(">>>ENTER YOUR TEXT HERE >><< NOT NESSESARY <<< MINE    HAS RANDOM TEXT 144 CELLS DOWN THIS LINE ");
uint8_t linetwolen = strlen_P(linetwo);
lcd_line_three();
lcd_write_string(PSTR("THE LARGEST MAMMAL  "));
lcd_line_four();
lcd_write_string(PSTR("   THE LARGEST BRAIN"));

uint8_t scroll_time = 0;

To the first line after:

twinkle(){

At line 311. Keeping my fingers crossed, but if it doesn't work let me know what the compiler errors are and I'll try to help.

March 29, 2012
by Farmerjoecoledge
Farmerjoecoledge's Avatar

bolt, you sure you don't mean line 307, and what happened to 'void'?

'nothing to be done for all' at 'twinkle' more errors later.

one successful flash, the heart code worked but the scroll didn't this time.

March 29, 2012
by pcbolt
pcbolt's Avatar

Joe -

You'll have to keep "void" in front of "twinkle(){". Line 307 or 311 should work, go with 307. I might have to take a look at your "Makefile" to see if that is set-up correctly. What were the "more errors later"?

March 29, 2012
by Farmerjoecoledge
Farmerjoecoledge's Avatar

March 29, 2012
by Farmerjoecoledge
Farmerjoecoledge's Avatar

One more time...

Yeah, it worked, three yrs later, I finally got a pic up.

So that's just adding the block of code, nothing else. Too strange again, shoots out a 'nothing to be done for all' and carries right on.

March 29, 2012
by pcbolt
pcbolt's Avatar

Wow that's hard to read. I can make out some of the text though. The "nothing to be done for all" is actually referring to the "all" tag inside the "libnerdkits" makefile. Since you're not changing any of the "libnerdkits" source files (lcd.c, delay.c etc) nothing needs to be done...so that isn't an error at all. I can't make out those warning messages. It would be helpful if I saw what the "twinkle()" code looks like after modifications and what some of the warnings are. It looks like the "while(1)" loop isn't getting called, so there might be a closing brace somewhere it shouldn't be.

March 29, 2012
by Farmerjoecoledge
Farmerjoecoledge's Avatar

Stupid linux screen pics, I reduced it by 70% just so it wouldn't take up the whole page, now you can't read it, another, too much.

I got a clue... part of the code made it...

Just got to scroll the second line.

March 29, 2012
by pcbolt
pcbolt's Avatar

Looks great Joe. Hopefully the scroll bug will get tracked down.

March 30, 2012
by Farmerjoecoledge
Farmerjoecoledge's Avatar

Before I go away, could you tell me why there's no 'twinkle' in the lights? I was staring at it last night, and I pretty sure it never did 'twinkle' goes through the bright and dimming cycle reapeats every 10secs or so. That's the heart.c by itself.

Post a Reply

Please log in to post a reply.

Did you know that NerdKits has been featured in the MIT Undergraduate Research Journal? Learn more...