added some examples, shortened some lcd functions

This commit is contained in:
2015-04-29 18:29:52 +02:00
parent c75086ea00
commit 161b2ce88f
7 changed files with 140 additions and 43 deletions
+2 -2
View File
@@ -11,14 +11,14 @@ EFUSE = 0x05
## === Source files ===
# Main C file
MAIN = uart_isr.c
MAIN = lcd_test.c
# Extra C files in this folder
LOCAL_SOURCE =
# Library directory (with C files)
EXTRA_SOURCE_DIR = lib/
# C files in the library directory
EXTRA_SOURCE_FILES = uart.c
EXTRA_SOURCE_FILES = uart.c lcd.c
## === Programmer ===
+13
View File
@@ -0,0 +1,13 @@
#pragma once
// Pin config file for LCD.
#include "lib/arduino_pins.h"
#define LCD_RS D2
#define LCD_RW D3
#define LCD_E D4
#define LCD_D4 D5
#define LCD_D5 D6
#define LCD_D6 D7
#define LCD_D7 D8
+58
View File
@@ -0,0 +1,58 @@
//
// Example of basic LCD usage
//
#include <avr/io.h>
#include <avr/pgmspace.h>
#include <util/delay.h>
#include "lib/calc.h"
#include "lib/lcd.h"
// Bytes for custom glyph
// Here's a good glyph generator you can use:
// http://omerk.github.io/lcdchargen/
const uint8_t glyph[] PROGMEM = {
0b00000,
0b00111,
0b01101,
0b11101,
0b10001,
0b10001,
0b10001,
0b11111
};
void main()
{
lcd_init();
// Define custom glyph at character 0
lcd_glyph_pgm(0, glyph);
// After writing a glyph, the address is changed
// So we need to fix that:
lcd_xy(0, 0);
// Print a string
lcd_puts("Hello");
// Use _pgm for strings in program memory
// Here we print string at position xy
lcd_puts_xy_pgm(0, 1, PSTR("String from PGM "));
// print the custom glyph
lcd_putc(0);
// enable blink/bar cursor type
lcd_cursor(CURSOR_BOTH);
lcd_puts_xy(5, 2, "Third line?");
lcd_puts_xy(3, 3, "Fourth line!");
// end
while(1);
}
+4 -1
View File
@@ -1,8 +1,11 @@
//
// Example of UART with interrupts
//
#include <avr/io.h>
#include <util/delay.h>
#include <avr/pgmspace.h>
#include <avr/interrupt.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
+11 -6
View File
@@ -1,8 +1,11 @@
//
// Example of basic UART usage
//
#include <avr/io.h>
#include <util/delay.h>
#include <avr/pgmspace.h>
#include <avr/interrupt.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
@@ -21,8 +24,8 @@ void main()
// Printing a string
uart_puts("Simple UART example!\r\n");
// You can put your string literals in the program memory
// and use the _pgm variant:
// Use _pgm for strings in program memory
// (PSTR macro is defined in avr/pgmspace.h)
uart_puts_pgm(PSTR("Program memory string example\r\n"));
// print a char. This is an alias for uart_tx
@@ -32,24 +35,26 @@ void main()
uart_nl();
// Printing numbers is also easy
// Look in the library file for more info
// Look in `uart.h` for more info
uart_putn(123);
uart_nl();
// Print int as float (adds decimal point)
// Print int as float (adds decimal point at 4th place from the end)
uart_puti(31415, 4);
uart_nl();
// --- receive example ---
// Example of listening for input
while(1) {
// If something is received
if (uart_rx_ready()) {
// Get the received byte
char c = uart_rx();
// Send it back, twice
uart_tx(c);
uart_tx(c);