lect2_avrboard_sol - CS331 Overview This lecture...

Info iconThis preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon
CS331 Fall 1997 1 1 Overview This lecture • Programming overview • LCD screen usage • Digital input and output • The content of this lecture is covered by the lab manual pp. 4-14. 2 Programming the Microcontroller All coding done in C and compiled by GCC for the ATmega16 target. Standard library functions are provided by the GNU AVR Libc project. Makefile template is provided to compile, link, and upload a program.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
CS331 Fall 1997 2 3 Using the LCD Screen Low-level communication with the display is complicated, so the following functions are provided. AVR Libc’s printf() void lcd_locate(uint8_t row, uint8_t column) Move the cursor to the specified row (0 - 7) and column (0 - 20). void lcd_clear() Clear the entire LCD. void lcd_clear_row(uint8_t row) Clear the specified row (0 - 7) on the LCD. 4 helloworld.c #include <avr/io.h> #include <stdio.h> #include <avr/interrupt.h> #include <avr/signal.h> #include "avrboard.h" int main() { cli(); // Disable interrupts ports_initialize(); // Initialize the I/O ports lcd_initialize(); // Initialize and turn on the LCD fdevopen(lcd_putc, NULL, 0); // Direct stdout to the LCD sei(); // Enable interrupts printf("Hello\n"); // Print some text to the LCD printf("world!"); while (1); // Spin forever }
Background image of page 2
CS331 Fall 1997 3 5 Data Types uint8_t 8-bit unsigned integer uint16_t 16-bit unsigned integer uint32_t 32-bit unsigned integer uint64_t 64-bit unsigned integer int8_t 8-bit signed integer int16_t 16-bit signed integer int32_t 32-bit signed integer int64_t 64-bit signed integer char 8-bit (signed) character double 32-bit floating point value Should I be careful when choosing the data type? 6 Data Types uint8_t 8-bit unsigned integer uint16_t 16-bit unsigned integer uint32_t 32-bit unsigned integer uint64_t 64-bit unsigned integer int8_t 8-bit signed integer int16_t 16-bit signed integer int32_t 32-bit signed integer int64_t 64-bit signed integer char 8-bit (signed) character double 32-bit floating point value Be careful when choosing the data type: as an example, performing shifts on signed integer is not advised because (according to ANSI C) the result is machine dependent (arithmetic shift or logic shift).
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
CS331 Fall 1997 4 7 Bitwise Operations ~ Bitwise inverse (one's compliment) ~00101111 Æ 11010000 &B i t w i s e
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 13

lect2_avrboard_sol - CS331 Overview This lecture...

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online