MCU = atmega32u4
FORMAT = ihex
TARGET = cooler
-SRC = $(TARGET).c usb/usb_serial.c ../../lcdlib/lcd-color-graphic.c ../../lcdlib/font.c \
- ../../lcdlib/Fonts/digits_24px.c ../../lcdlib/Fonts/digits_32px.c ../../lcdlib/Fonts/font_proportional_16px.c ../../lcdlib/Fonts/symbols_16px.c ../../lcdlib/Fonts/font_proportional_8px.c
+SRC = $(TARGET).c usb/usb_serial.c lcdlib/lcd-color-graphic.c lcdlib/font.c \
+ lcdlib/Fonts/digits_24px.c lcdlib/Fonts/digits_32px.c lcdlib/Fonts/font_proportional_16px.c lcdlib/Fonts/font_proportional_8px.c lcdlib/Fonts/symbols_16px.c
ASRC =
-OPT = s
+OPT = 2
# Name of this Makefile (used for "make depend").
MAKEFILE = Makefile
CDEBUG = -g$(DEBUG)
-CWARN = -Wall -Wstrict-prototypes
-CTUNING = -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums
+CWARN = -Wall -Wstrict-prototypes
+CTUNING = -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -Wl,--relax
#CEXTRA = -Wa,-adhlns=$(<:.c=.lst)
-CFLAGS = $(CDEBUG) $(CDEFS) $(CINCS) -O$(OPT) $(CWARN) $(CSTANDARD) $(CEXTRA)
+CFLAGS = $(CDEBUG) $(CDEFS) $(CINCS) -O$(OPT) $(CWARN) $(CSTANDARD) $(CEXTRA) $(CTUNING)
#ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs
# Programming support using avrdude. Settings and variables.
-AVRDUDE_PROGRAMMER = dragon_isp
+AVRDUDE_PROGRAMMER = dragon_jtag
AVRDUDE_PORT = usb
AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex
# Uncomment the following if you do /not/ wish a verification to be
# performed after programming the device.
-#AVRDUDE_NO_VERIFY = -V
+AVRDUDE_NO_VERIFY = -V
# Increase verbosity level. Please use this when submitting bug
# reports about avrdude. See <http://savannah.nongnu.org/projects/avrdude>
# Default target.
-all: build
+all: build size
build: elf hex eep
$(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM)
-
+size:
+ $(SIZE) -C --mcu=$(MCU) $(TARGET).elf
# Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.
COFFCONVERT=$(OBJCOPY) --debugging \
-#define F_CPU 8000000UL
+// #define F_CPU 8000000UL
#include <avr/interrupt.h>
#include <util/delay.h>
#include <avr/io.h>
+#include <stdlib.h>
#include "usb/usb_serial.h"
+#include "lcdlib/lcd-color-graphic.h"
+#include "lcdlib/font.h"
+#define YELLOW_ON() PORTB &= ~0x1
+#define YELLOW_OFF() PORTB |= 0x1
+#define GREEN_ON() PORTD &= ~(1<<PD5)
+#define GREEN_OFF() PORTD |= (1<<PD5)
+#define TOP_BACKGROUND() lcd_set_background(0x03,0x04,0x05)
+#define BOTTOM_BACKGROUND() lcd_set_background(0x00,0x00,0x00)
+#define FIRST_VALUE_FOREGROUND() lcd_set_foreground(0x1f,0x3f,0x0e);lcd_set_background(0x03,0x04,0x05)
+#define SECOND_VALUE_FOREGROUND() lcd_set_foreground(0x0e,0x2e,0x1f);lcd_set_background(0x03,0x04,0x05)
+#define FIRST_VALUE_BACKGROUND() lcd_set_background(0x1f,0x3f,0x0e)
+#define SECOND_VALUE_BACKGROUND() lcd_set_background(0x0e,0x2e,0x1f)
+#define AXES_COLOR() lcd_set_foreground(0x1f,0x3f,0x1f);
+
+
+#define BUFFERSIZE 16
+#define STORAGESIZE 300
+const uint8_t lut[16] = {0,1,1,2,3,3,4,4,5,5,6,7,7,8,9,9};
+uint8_t buffer[BUFFERSIZE];
+uint8_t recvpointer = 0;
+int16_t values[2][STORAGESIZE];
+uint16_t valuepointer[2] = {0};
+uint16_t lastvalues[2] = {0,0};
+
+#define MINX 19
+#define MAXX 318
+#define MINY 100
+#define MAXY 220
+void draw(void) {
+ uint16_t c = MINX;
+ uint16_t p = valuepointer[0];
+ FIRST_VALUE_FOREGROUND();
+ lcd_set_background(0x00,0x00,0x00);
+ lcd_set_page(0,239);
+ lcd_set_column(0,319);
+ do{
+ uint16_t y = values[0][p];
+ y = y*3;
+ y >>= 4;
+ y = 190-y;
+ lcd_set_pixel_col_xy(c+1,y,background);
+ lcd_set_pixel_col_xy(c,y,foreground);
+ p++;
+ if(p>= STORAGESIZE) p = 0;
+ }while(++c<MAXX);
+ }
+
+
+void init_spi_lcd(void) {
+ SPCR = 0 << SPIE | 1 << SPE | 0 << DORD | 1 << MSTR | 1 << CPOL | 1 << CPHA | 0 << SPR1 | 0 << SPR0;
+ SPSR = 1 << SPI2X;
+ SPDR = LCD_NOP; //Do not use 0 here, only LCD_NOP is allowed!
+ }
+
+void init(void) {
+ CLKPR = (1<<CLKPCE);
+ CLKPR = 0x01; //prescaler 2
+ PRR0 = 0;
+ DDRB |= (1<<PB0) | (1<<PB1) | (1<<PB2);
+ DDRD |= (1<<PD5);
+ YELLOW_OFF();
+ GREEN_OFF();
+ }
+
+
+uint8_t hex2int(char c) {
+ if(c >= '0' && c<='9') return c-'0';
+ if(c >= 'a' && c<='f') return c-'a'+10;
+ if(c >= 'A' && c<='F') return c-'A'+10;
+ return -1;
+ }
+
+void showTemp(uint8_t place, int16_t val) {
+ uint8_t neg = 0;
+ int16_t t = val;
+ uint8_t x,y;
+ if(val<0) {
+ neg = 1;
+ t = val * -1;
+ }
+
+ y = t & 0xF;
+ x = t >> 4;
+
+ lcd_set_font(FONT_DIGITS_32,SPACING);
+ TOP_BACKGROUND();
+
+ if(place == 0) {
+ FIRST_VALUE_FOREGROUND();
+ if(lastvalues[place]<=-160) {
+ if(val >-160)
+ lcd_set_area_xy(190,210,23,28);
+ }
+ else if (lastvalues[place]<0) {
+ if(val>0)
+ lcd_set_area_xy(220,240,23,28);
+ }
+
+ if(x<10 && (lastvalues[place]<=-160 || lastvalues[place]>=160))
+ lcd_set_area_xy(210,246,8,39);
+
+ FIRST_VALUE_BACKGROUND();
+ if(neg) {
+ if(x>=10 && lastvalues[place]>-160)
+ lcd_set_area_xy(190,210,23,28);
+ else if(x<10 && (lastvalues[place]<=-160 || lastvalues[place]>=0))
+ lcd_set_area_xy(220,240,23,28);
+ }
+ if(x>=10) lcd_moveto_xy(8,220);
+ else lcd_moveto_xy(8,249);
+ }
+ else {
+ SECOND_VALUE_FOREGROUND();
+ lcd_set_area_xy(190,210,63,68);
+ lcd_set_area_xy(210,246,48,79);
+
+ SECOND_VALUE_BACKGROUND();
+ if(neg) {
+ if(x>=10) lcd_set_area_xy(190,210,63,68);
+ else lcd_set_area_xy(220,240,63,68);
+ }
+ if(x>=10) lcd_moveto_xy(48,220);
+ else lcd_moveto_xy(48,249);
+ }
+
+ TOP_BACKGROUND();
+ lcd_put_int(x);
+ if(!place)lcd_moveto_xy(8,289);
+ else lcd_moveto_xy(48,289);
+ lcd_putc(lut[y]+'0');
+
+ lastvalues[place] = val;
+ }
+
+
+
+void pushvalue(uint8_t i, int16_t v) {
+ if(valuepointer[i] == STORAGESIZE-1) valuepointer[i] = 0;
+ else valuepointer[i]++;
+ values[i][valuepointer[i]] = v;
+ showTemp(i,v);
+ draw();
+ }
+
+void printAxes(void) {
+ AXES_COLOR();
+ BOTTOM_BACKGROUND();
+ lcd_set_area_xy(20,319,100,220);
+ TOP_BACKGROUND();
+ lcd_set_font(FONT_PROP_16,NORMAL);
+ lcd_putstr_xy_P(PSTR("-10"),216,0);
+ lcd_putstr_xy_P(PSTR(" 30"),96,0);
+ lcd_putstr_xy_P(PSTR("-5"),224,20);
+ lcd_putstr_xy_P(PSTR("0"),224,300);
+ lcd_draw_line(MINX,MINX,MINY-1,MAXY+1);
+ lcd_draw_line(MINX,MAXX,MINY-1,MINY-1);
+ lcd_draw_line(MINX,MAXX,MAXY+1,MAXY+1);
+ lcd_draw_line(MAXX+1,MAXX+1,MINY-1,MAXY+1);
+ lcd_set_font(FONT_PROP_8,NORMAL);
+ lcd_putstr_xy_P(PSTR("minutes"),228,150);
+ lcd_putstr_xy_P(PSTR("T"),160,10);
+
+ FIRST_VALUE_FOREGROUND();
+ lcd_set_font(FONT_PROP_16,NORMAL);
+ lcd_putstr_xy_P(PSTR("is"),8,190);
+ lcd_set_font(FONT_DIGITS_32,SPACING);
+ lcd_moveto_xy(8,278);
+ lcd_putc('.');
+ SECOND_VALUE_FOREGROUND();
+ lcd_set_font(FONT_PROP_16,NORMAL);
+ lcd_putstr_xy_P(PSTR("set"),48,190);
+ lcd_set_font(FONT_DIGITS_32,SPACING);
+ lcd_moveto_xy(48,278);
+ lcd_putc('.');
+
+ }
+
+
+
__attribute__((naked)) int main(void) {
-// lcd_init();
+ init();
usb_init();
+ lcd_init();
+
+ lcd_command_1(LCD_MIRROR, LCD_BGR | LCD_FLIP_XY);
+ lcd_command(LCD_ON);
+
+ TOP_BACKGROUND();
+ lcd_set_area_xy(0, 0x13F, 0, 0xEF);
+
+ lcd_set_foreground(0x1f,0x3f,0x1f);
+ lcd_set_font(FONT_PROP_16,DOUBLE_HEIGHT|SPACING);
+ lcd_putstr_xy_P(PSTR("Cooling Control"),26,30);
+
+
+
+ pushvalue(0,(17*16+5));
+ pushvalue(1,-(8*16+3));
+ printAxes();
+
+
+ while (1) {
+ int n = usb_serial_getchar();
+ if (n >= 0) {
+ buffer[recvpointer++] = n;
+ if(recvpointer>BUFFERSIZE) {
+ recvpointer = 0;
+ }
- while (1) {
+ if(n == 10 && recvpointer >= 8 && buffer[0] == 'S' && buffer[1] == 'E' && buffer[2] == 'T') { //SETnsvvv
+ uint16_t t = hex2int(buffer[5])*256 + hex2int(buffer[6])*16 + hex2int(buffer[7]);
+ if (buffer[4] == '-') t = t*-1;
+ pushvalue(hex2int(buffer[3]),t);
+ }
+ if(n==10) {
+ usb_serial_write(buffer,recvpointer);
+ recvpointer = 0;
+ }
+ }
}
}
\ No newline at end of file
}
//write character
+ uint8_t cont = 0;
do {
for(i=(row>>hc); i<char_width*font_height; i+=font_height) {
tmp = pgm_read_byte(tableposition+i);
- if(row == char_final_height-1)
+ if(ul && row == char_final_height-1)
tmp |= ul;
if(hc)
tmp = double_bits((row&1),tmp);
if(inv)
tmp = ~tmp;
- LCD_WRITE(tmp);
+ LCD_WRITE(tmp,cont);
+ cont = 1;
if(wc)
- LCD_WRITE(tmp);
+ LCD_WRITE(tmp,cont);
}
if (free_space) {
uint8_t c = inv;
if(hc)
c ^= ul>>1;
}
- for(uint8_t x = free_space; x>0;x--) {
- LCD_WRITE(c);
+ for(uint8_t x = free_space<<wc; x>0;x--) {
+ LCD_WRITE(c,cont);
}
}
LCD_MOVE(1,-char_final_width);
+ cont = 0;
} while (++row < char_final_height);
//move cursor to upper right corner of character
* the string from program memory. The position of the string on the display
* is selected by page / col.
*/
-uint16_t lcd_put_string_xy_P(FONT_P font, uint8_t style, PGM_P str,uint8_t page, uint8_t col) {
+uint16_t lcd_put_string_xy_P(FONT_P font, uint8_t style, PGM_P str,uint16_t page, uint16_t col) {
LCD_MOVE_TO(page,col);
return lcd_put_string_P(font,style,str);
}
* the string from main memory. The position of the string on the display
* is selected by page / col.
*/
-uint8_t lcd_put_char_xy(FONT_P font, uint8_t style, char character, uint8_t page, uint8_t col) {
+uint8_t lcd_put_char_xy(FONT_P font, uint8_t style, char character, uint16_t page, uint16_t col) {
LCD_MOVE_TO(page,col);
return lcd_put_char(font,style,character);
}
/******************************************************************************
* Outputs a character on the display, using the global font and style
*/
-uint8_t lcd_putc_xy(char c, uint8_t page, uint8_t col) {
+uint8_t lcd_putc_xy(char c, uint16_t page, uint16_t col) {
return lcd_put_char_xy(global_font_select, global_font_style, c, page, col);
}
* Outputs a string on the display, using the global font and style at the
* given position
*/
-uint16_t lcd_putstr_xy_P(PGM_P str, uint8_t page, uint8_t col) {
+uint16_t lcd_putstr_xy_P(PGM_P str, uint16_t page, uint16_t col) {
return lcd_put_string_xy_P(global_font_select, global_font_style, str, page, col);
}
#include <stdio.h>
//Include your LCD graphics library here
-#include "dogm-graphic.h"
+#include "lcd-color-graphic.h"
//declare font info structure defined below
struct font_info;
typedef const struct font_info * FONT_P;
#define FONTS_INCLUDE_font_proportional_16px font_proportional_16px
#define FONTS_INCLUDE_font_proportional_8px font_proportional_8px
-#define FONTS_INCLUDE_font_fixed_8px font_fixed_8px
-#define FONTS_INCLUDE_font_fixed_16px font_fixed_16px
-#define FONTS_INCLUDE_symbols_8px symbols_8px
-#define FONTS_INCLUDE_symbols_16px symbols_16px
-#define FONTS_INCLUDE_digits_24px digits_24px
+//#define FONTS_INCLUDE_font_fixed_8px font_fixed_8px
+// #define FONTS_INCLUDE_font_fixed_16px font_fixed_16px
+// #define FONTS_INCLUDE_symbols_8px symbols_8px
+// #define FONTS_INCLUDE_symbols_16px symbols_16px
+// #define FONTS_INCLUDE_digits_24px digits_24px
#define FONTS_INCLUDE_digits_32px digits_32px
//Set to 1 to include functions for direct output of integer & float values
-#define INCLUDE_FLOAT_OUTPUT 0
+// #define INCLUDE_FLOAT_OUTPUT 1
#define INCLUDE_INTEGER_OUTPUT 1
#define LCD_MOVE(x,y) lcd_move_xy((x),(y)) //relative cursor movement
#define LCD_MOVE_TO(x,y) lcd_moveto_xy((x),(y)) //absolute cursor movement
-#define LCD_WRITE(x) lcd_data((x)) //write data to display
+#define LCD_WRITE(x,c) lcd_write_font_byte(x,c) //lcd_data((x)) //write data to display
//Functions to read the current position as provided by the LCD library
#define LCD_CURRENT_COL() lcd_get_position_column()
uint16_t lcd_put_string_length(FONT_P font, uint8_t style, char* str, uint8_t length);
uint16_t lcd_put_string_P (FONT_P font, uint8_t style, PGM_P str);
uint8_t lcd_put_char (FONT_P font, uint8_t style, char c);
-uint16_t lcd_put_string_xy_P (FONT_P font, uint8_t style, PGM_P str, uint8_t page, uint8_t col);
-uint8_t lcd_put_char_xy (FONT_P font, uint8_t style, char character, uint8_t page, uint8_t col);
+uint16_t lcd_put_string_xy_P (FONT_P font, uint8_t style, PGM_P str, uint16_t page, uint16_t col);
+uint8_t lcd_put_char_xy (FONT_P font, uint8_t style, char character, uint16_t page, uint16_t col);
void lcd_set_font (FONT_P font, uint8_t style);
uint8_t lcd_putc (char c);
-uint8_t lcd_putc_xy (char c, uint8_t page, uint8_t col);
+uint8_t lcd_putc_xy (char c, uint16_t page, uint16_t col);
uint16_t lcd_putstr (char* str);
uint16_t lcd_putstr_P (PGM_P str);
-uint16_t lcd_putstr_xy_P (PGM_P str, uint8_t page, uint8_t col);
+uint16_t lcd_putstr_xy_P (PGM_P str, uint16_t page, uint16_t col);
#if INCLUDE_INTEGER_OUTPUT == 1
uint16_t lcd_put_long (int32_t integer);
* Background is used as background, e.g. when writing fonts.
*/
-color_t foreground = {.red=0x1F, .green=0x3F, .blue=0x1F};
-color_t background = {.red=0, .green=0, .blue=0};
+color_t foreground;
+color_t background;
/******************************************************************************
LCD_SET_PIN_DIRECTIONS(); //set outputs
_delay_ms(1);
LCD_INIT_SPI(); //Initialize SPI Interface
+ LCD_UNSELECT();
_delay_ms(50);
LCD_RESET_ON(); //Apply Reset to the Display Controller
_delay_ms(100);
LCD_SELECT(); //Switches chip select on
lcd_command(LCD_SLEEP_OUT); //Wake up LCD
_delay_ms(70);
+ lcd_command_1(LCD_COLOR_MODE,LCD_16BIT);
return;
}
/******************************************************************************
* Sends a command to the display
*/
-inline void lcd_command(uint8_t c) {
- spi_wait_for_idle();
- LCD_CMD();
- spi_write(c);
- }
+// inline void lcd_command(uint8_t c) {
+// spi_wait_for_idle();
+// LCD_CMD();
+// spi_write(c);
+// }
+
+
+/******************************************************************************
+ * Sends a data word to the display
+ */
+// inline void lcd_data(uint8_t c) {
+// spi_wait_for_idle();
+// LCD_DATA();
+// spi_write(c);
+// }
+
/******************************************************************************
* Sends a command with one argument
lcd_command(c);
lcd_data(data);
}
-
-/******************************************************************************
- * Sends a data word to the display
- */
-inline void lcd_data(uint8_t c) {
- spi_wait_for_idle();
- LCD_DATA();
- spi_write(c);
-}
-
-
/******************************************************************************
* Stores the main drawing color for later use
*/
inline void lcd_set_foreground(uint8_t r, uint8_t g, uint8_t b) {
- foreground.red = r;
- foreground.green = g;
- foreground.blue = b;
+ uint16_t t = r<<11 | g<<5 | b;
+ foreground.c1 = t>>8;
+ foreground.c2 = t;
}
* Stores the background color for later use
*/
inline void lcd_set_background(uint8_t r, uint8_t g, uint8_t b) {
- background.red = r;
- background.green = g;
- background.blue = b;
+ uint16_t t = r<<11 | g<<5 | b;
+ background.c1 = t>>8;
+ background.c2 = t;
}
inline void lcd_set_column(uint16_t start, uint16_t end) {
lcd_command(LCD_SET_COLUMN);
lcd_data(start >> 8);
- lcd_data(start);
- lcd_data(end >> 8);
- lcd_data(end);
+ lcd_data_cont(start);
+ lcd_data_cont(end >> 8);
+ lcd_data_cont(end);
}
-
+inline void lcd_set_column_short(uint16_t start) {
+ lcd_command(LCD_SET_COLUMN);
+ lcd_data(start >> 8);
+ lcd_data_cont(start);
+ }
+
/******************************************************************************
* Sets the page range used for the next write operation
*/
inline void lcd_set_page(uint16_t start, uint16_t end) {
lcd_command(LCD_SET_PAGE);
lcd_data(start >> 8);
- lcd_data(start);
- lcd_data(end >> 8);
- lcd_data(end);
+ lcd_data_cont(start);
+ lcd_data_cont(end >> 8);
+ lcd_data_cont(end);
+ }
+inline void lcd_set_page_short(uint16_t start) {
+ lcd_command(LCD_SET_PAGE);
+ lcd_data(start >> 8);
+ lcd_data_cont(start);
}
/******************************************************************************
* Writes a pixel to the display using 16 Bit color mode
*/
inline void lcd_send_pixel(color_t c) {
- lcd_data((c.red<<3) | (c.green>>3));
- lcd_data((c.green<<5) | c.blue);
+ lcd_data(c.c1);
+ lcd_data_cont(c.c2);
}
/******************************************************************************
lcd_send_pixel(foreground);
}
-
+/******************************************************************************
+ * Sets a pixel at a given position
+ */
+inline void lcd_set_pixel_col_xy(uint16_t column, uint16_t page, color_t col) {
+ lcd_set_page_short(page);
+ lcd_set_column_short(column);
+ lcd_command(LCD_WRITE_MEM);
+ lcd_send_pixel(col);
+ }
+
/******************************************************************************
* This function sets an area of the screen to a given color
* col0 - left edge of the area
uint16_t lcd_inc_page(int16_t s) {
uint16_t p = lcd_current_page;
p += s;
- if (p > LCD_HEIGHT/8)
+ if (p > LCD_HEIGHT)
p = 0;
lcd_current_page = p;
* Moves the cursor relative to the current position
* pages - number of pages to move
* columns - number of columns to move
+ * for use with the font library only
*/
void lcd_move_xy(int16_t pages, int16_t columns) {
- lcd_moveto_xy(lcd_inc_page(pages),lcd_inc_column(columns));
+ lcd_moveto_xy(lcd_inc_page(pages*8),lcd_inc_column(columns));
}
/******************************************************************************
* Takes a vertical byte from the font generator and prints it on the display
* b - Bit pattern to display
+ * c - continue writing in same page
*/
-void lcd_write_font_byte(uint8_t b) {
- lcd_set_page(8*lcd_current_page,8*lcd_current_page+8);
+void lcd_write_font_byte(uint8_t b, uint8_t c) {
+ if(!c) {
+ lcd_set_page(lcd_current_page,lcd_current_page+8);
+ }
lcd_set_column(lcd_current_column,lcd_current_column);
lcd_command(LCD_WRITE_MEM);
for(uint8_t i=0;i<8;i++) {
}
lcd_inc_column(1);
}
+
+
+/******************************************************************************
+ * Draws a line according to Bresenham (from wikipedia)
+ */
+void lcd_draw_line(uint16_t x0, uint16_t x1, uint16_t y0, uint16_t y1) {
+ int16_t dx = abs(x1-x0);
+ int16_t sx = x0<x1 ? 1 : -1;
+ int16_t dy = -abs(y1-y0);
+ int16_t sy = y0<y1 ? 1 : -1;
+ int16_t err = dx+dy, e2; /* error value e_xy */
+
+ for(;;){ /* loop */
+ lcd_set_pixel_xy(x0,y0);
+ if (x0==x1 && y0==y1) break;
+ e2 = 2*err;
+ if (e2 > dy) { err += dy; x0 += sx; } /* e_xy+e_x > 0 */
+ if (e2 < dx) { err += dx; y0 += sy; } /* e_xy+e_y < 0 */
+ }
+ }
+
\ No newline at end of file
#include <string.h>
#include <util/delay.h>
#include <avr/pgmspace.h>
-
+#include <stdlib.h>
/*****************************************************************************
* BEGIN CONFIG BLOCK
*****************************************************************************/
-#define LCD_WIDTH 240
-#define LCD_HEIGHT 320
+#define LCD_WIDTH 320
+#define LCD_HEIGHT 240
//Should chip select (CS) be used?
#define LCD_USE_CHIPSELECT 1
//CD Port
#define PORT_DC PORTB
#define DDR_DC DDRB
-#define PIN_DC 0
+#define PIN_DC 6
//Reset Port
-#define PORT_RST PORTA
-#define DDR_RST DDRA
+#define PORT_RST PORTB
+#define DDR_RST DDRB
#define PIN_RST 4
//Chip select
#if LCD_USE_CHIPSELECT == 1
#define PORT_CS PORTB
#define DDR_CS DDRB
- #define PIN_CS 1
+ #define PIN_CS 5
#endif
//SPI routines
#define LCD_INIT_SPI() init_spi_lcd()
//Define a function that waits until SPI interface is idle
-#define spi_wait_for_idle() while(! (SPSR0 & _BV(SPIF0)));
+#define spi_wait_for_idle() asm volatile ("nop");while(! (SPSR & _BV(SPIF)));
//Define how to write to SPI data register
-#define spi_write(i) SPDR0 = i
+#define spi_write(i) SPDR = i
/*Example SPI setup (Atmega162)
*init spi: msb first, update on falling edge , read on rising edge, 9 MHz
//Color struct - no bit fields are used for better performance (i.e. bit shifts
//can be done while waiting for SPI, not while preparing to write the pixel)
typedef struct {
- uint8_t red;
- uint8_t green;
- uint8_t blue;
+ uint8_t c1;
+ uint8_t c2;
} color_t;
+#define lcd_data(c) spi_wait_for_idle();LCD_DATA();spi_write(c)
+#define lcd_data_cont(c) spi_wait_for_idle();spi_write(c)
+#define lcd_command(c) spi_wait_for_idle();LCD_CMD();spi_write(c)
+
+ color_t foreground;
+ color_t background;
+
/*****************************************************************************
* Public Functions
*****************************************************************************/
void lcd_init(void);
//write data word or command to the LCD
- void lcd_data (uint8_t data);
- void lcd_command (uint8_t cmd);
+// void lcd_data (uint8_t data) ;
+// void lcd_command (uint8_t cmd);
void lcd_command_1 (uint8_t cmd, uint8_t data);
//Set the drawing and background colors
//Set a pixel at a given location to the foreground color
void lcd_set_pixel_xy(uint16_t column, uint16_t page);
+ void lcd_set_pixel_col_xy(uint16_t column, uint16_t page, color_t col);
//Set an area to the background color
void lcd_set_area_xy(uint16_t col0, uint16_t col1, uint16_t page0, uint16_t page1);
-
+//Draw a straight line
+ void lcd_draw_line(uint16_t x1, uint16_t x2, uint16_t y1, uint16_t y2);
//Text functions are included in font.c / font.h
extern uint16_t lcd_current_column;
static inline uint16_t lcd_get_position_page(void) {return lcd_current_page;}
static inline uint16_t lcd_get_position_column(void) {return lcd_current_column;}
- void lcd_write_font_byte(uint8_t b);
+ void lcd_write_font_byte(uint8_t b, uint8_t c);
/*****************************************************************************
--- /dev/null
+#!/usr/bin/perl
+use Time::HiRes qw(usleep);
+
+open (MYFILE, '>>/dev/Xmatter_Chiller_00001');
+
+for(my $i = 0;$i<300;$i++) {
+ my $val = sin($i/180*3.14)*16*5.2-80;
+ my $cmd = sprintf("SET0%s%02x%01x\n",($val<0)?'-':'+',abs($val)>>4&0xff,abs($val)&0xF);
+ print MYFILE $cmd;
+# usleep(300000);
+ }
\ No newline at end of file
// You can change these to give your code its own name. On Windows,
// these are only used before an INF file (driver install) is loaded.
-#define STR_MANUFACTURER L"TRB3"
-#define STR_PRODUCT L"DAQi"
+#define STR_MANUFACTURER L"Xmatter"
+#define STR_PRODUCT L"Chiller"
// All USB serial devices are supposed to have a serial number
// (according to Microsoft). On windows, a new COM port is created