LED test code
This commit is contained in:
		
							
								
								
									
										2
									
								
								Makefile
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								Makefile
									
									
									
									
									
								
							@@ -26,7 +26,7 @@ $(PRG).elf: $(OBJ)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
# dependency:
 | 
					# dependency:
 | 
				
			||||||
rgbyteclock.o: timer.o lcd.o rgbyteclock.h rtc.o spi.o ledcontroller.o
 | 
					rgbyteclock.o: timer.o lcd.o rgbyteclock.h rtc.o spi.o ledcontroller.o
 | 
				
			||||||
main.o: rgbyteclock.o lcd.o spi.o ledcontroller.o
 | 
					main.o: rgbyteclock.o lcd.o spi.o ledcontroller.o rtc.o timer.o
 | 
				
			||||||
timer.o: timer.h
 | 
					timer.o: timer.h
 | 
				
			||||||
lcd.o: lcd.h timer.o
 | 
					lcd.o: lcd.h timer.o
 | 
				
			||||||
rtc.o: rtc.h
 | 
					rtc.o: rtc.h
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -10,6 +10,12 @@
 | 
				
			|||||||
 */
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * This module tries to control 15 RGB-LEDs
 | 
				
			||||||
 | 
					 * connected to three daisy-chained
 | 
				
			||||||
 | 
					 * LED1642GW-ICs from STM.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "ledcontroller.h"
 | 
					#include "ledcontroller.h"
 | 
				
			||||||
#include <string.h>
 | 
					#include <string.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -20,7 +26,7 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
static uint16_t ledbuffer[NUM_CHANNELS];
 | 
					static uint16_t ledbuffer[NUM_CHANNELS];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static int8_t get_channel_from_lednum(uint8_t lednum, uint8_t *channel_r, uint8_t *channel_g, uint8_t *channel_b)
 | 
					static int8_t map_lednum_to_channels(uint8_t lednum, uint8_t *channel_r, uint8_t *channel_g, uint8_t *channel_b)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
  uint8_t ret;
 | 
					  uint8_t ret;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -84,12 +90,12 @@ static void write_global_latch(uint16_t data)
 | 
				
			|||||||
void ledcontroller_init(void)
 | 
					void ledcontroller_init(void)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  PORTC &= ~(1<<PC3); // SCK
 | 
				
			||||||
 | 
					  PORTC &= ~(1<<PC4); // DATA
 | 
				
			||||||
 | 
					  PORTC &= ~(1<<PC2); // LE
 | 
				
			||||||
  DDRC |= (1<<PC3); // SCK
 | 
					  DDRC |= (1<<PC3); // SCK
 | 
				
			||||||
  DDRC |= (1<<PC4); // DATA
 | 
					  DDRC |= (1<<PC4); // DATA
 | 
				
			||||||
  DDRC |= (1<<PC2); // LE
 | 
					  DDRC |= (1<<PC2); // LE
 | 
				
			||||||
  PORTC |= (1<<PC3); // SCK
 | 
					 | 
				
			||||||
  PORTC |= (1<<PC4); // DATA
 | 
					 | 
				
			||||||
  PORTC |= (1<<PC2); // LE
 | 
					 | 
				
			||||||
  memset(ledbuffer, 0x00, sizeof(ledbuffer));
 | 
					  memset(ledbuffer, 0x00, sizeof(ledbuffer));
 | 
				
			||||||
  led_flush();
 | 
					  led_flush();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -99,7 +105,7 @@ void led_set(uint8_t lednum, uint16_t red, uint16_t green, uint16_t blue)
 | 
				
			|||||||
{
 | 
					{
 | 
				
			||||||
  uint8_t c_r, c_g, c_b;
 | 
					  uint8_t c_r, c_g, c_b;
 | 
				
			||||||
  
 | 
					  
 | 
				
			||||||
  if ( get_channel_from_lednum(lednum, &c_r, &c_g, &c_b) > 0 ) {
 | 
					  if ( map_lednum_to_channels(lednum, &c_r, &c_g, &c_b) > 0 ) {
 | 
				
			||||||
    ledbuffer[c_r] = red;
 | 
					    ledbuffer[c_r] = red;
 | 
				
			||||||
    ledbuffer[c_g] = green;
 | 
					    ledbuffer[c_g] = green;
 | 
				
			||||||
    ledbuffer[c_b] = blue;
 | 
					    ledbuffer[c_b] = blue;
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										4
									
								
								main.c
									
									
									
									
									
								
							
							
						
						
									
										4
									
								
								main.c
									
									
									
									
									
								
							@@ -10,18 +10,22 @@
 | 
				
			|||||||
 */
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <avr/io.h>
 | 
					#include <avr/io.h>
 | 
				
			||||||
 | 
					#include <avr/interrupt.h>
 | 
				
			||||||
#include "timer.h"
 | 
					#include "timer.h"
 | 
				
			||||||
#include "lcd.h"
 | 
					#include "lcd.h"
 | 
				
			||||||
#include "rgbyteclock.h"
 | 
					#include "rgbyteclock.h"
 | 
				
			||||||
#include "spi.h"
 | 
					#include "spi.h"
 | 
				
			||||||
#include "ledcontroller.h"
 | 
					#include "ledcontroller.h"
 | 
				
			||||||
 | 
					#include "rtc.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int main(void)
 | 
					int main(void)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
  
 | 
					  
 | 
				
			||||||
  timer_init();
 | 
					  timer_init();
 | 
				
			||||||
 | 
					  rtc_init(0);
 | 
				
			||||||
  spi_slave_init();
 | 
					  spi_slave_init();
 | 
				
			||||||
  ledcontroller_init();
 | 
					  ledcontroller_init();
 | 
				
			||||||
 | 
					  sei();
 | 
				
			||||||
  lcd_init();
 | 
					  lcd_init();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  rgbyteclock();
 | 
					  rgbyteclock();
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -12,14 +12,47 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "rgbyteclock.h"
 | 
					#include "rgbyteclock.h"
 | 
				
			||||||
 | 
					#include "timer.h"
 | 
				
			||||||
 | 
					#include "lcd.h"
 | 
				
			||||||
 | 
					#include "ledcontroller.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void rgbyteclock(void)
 | 
					void rgbyteclock(void)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
  while(1) {
 | 
					  while(1) {
 | 
				
			||||||
 | 
					    for (int i=0; i<15; i++) {
 | 
				
			||||||
 | 
					      led_set(i, 0x7ff, 0x00, 0x00);
 | 
				
			||||||
 | 
					      led_flush();
 | 
				
			||||||
 | 
					      timer_wait(200);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    for (int i=0; i<15; i++) {
 | 
				
			||||||
 | 
					      led_set(i, 0x00, 0x00, 0x00);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    led_flush();
 | 
				
			||||||
 | 
					    timer_wait(100);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    for (int i=0; i<15; i++) {
 | 
				
			||||||
 | 
					      led_set(i, 0x00, 0x7ff, 0x00);
 | 
				
			||||||
 | 
					      led_flush();
 | 
				
			||||||
 | 
					      timer_wait(200);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    for (int i=0; i<15; i++) {
 | 
				
			||||||
 | 
					      led_set(i, 0x00, 0x00, 0x00);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    led_flush();
 | 
				
			||||||
 | 
					    timer_wait(100);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    for (int i=0; i<15; i++) {
 | 
				
			||||||
 | 
					      led_set(i, 0x00, 0x00, 0x7ff);
 | 
				
			||||||
 | 
					      led_flush();
 | 
				
			||||||
 | 
					      timer_wait(200);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    for (int i=0; i<15; i++) {
 | 
				
			||||||
 | 
					      led_set(i, 0x00, 0x00, 0x00);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    led_flush();
 | 
				
			||||||
 | 
					    timer_wait(100);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -14,8 +14,6 @@
 | 
				
			|||||||
#define RGBYTECLOCK_H
 | 
					#define RGBYTECLOCK_H
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <avr/io.h>
 | 
					#include <avr/io.h>
 | 
				
			||||||
#include "timer.h"
 | 
					 | 
				
			||||||
#include "lcd.h"
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void rgbyteclock(void);
 | 
					void rgbyteclock(void);
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										2
									
								
								rtc.c
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								rtc.c
									
									
									
									
									
								
							@@ -37,8 +37,6 @@ void rtc_init(uint32_t rtc_time)
 | 
				
			|||||||
  TCCR2B = (1<<CS22)|(1<<CS20);
 | 
					  TCCR2B = (1<<CS22)|(1<<CS20);
 | 
				
			||||||
  
 | 
					  
 | 
				
			||||||
  TIMSK2 = (1<<TOIE2); // enable overflow interrupt
 | 
					  TIMSK2 = (1<<TOIE2); // enable overflow interrupt
 | 
				
			||||||
 | 
					 | 
				
			||||||
  sei();
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user