Examples 1 - 4 Lecture L2.2. // Example 1a: Turn on every other segment on 7-seg display #include /* common defines and macros */ #include /* derivative.

Slides:



Advertisements
Similar presentations
7-Segment Displays Lecture L6.1 Section 6.3. Turning on an LED.
Advertisements

C Examples 1.
1 Lab2: A/D Converter. 2 This circuit connects a variable voltage to an A/D port on the AVR mcu. Your software running on the AVR mcu will read the digital.
C and Assembler Subroutines: Using the LCD. Outline Basic structure of CW-created C programs for the HC12 How to incorporate assembly code How to use.
Example 11 Analog-to-Digital Converter Lecture L5.1.
C Language Programming. C has gradually replaced assembly language in many embedded applications. Data types –C has five basic data types: void, char,
8-Bit Timer/Counter 0 Counter/Timer 0 and 2 (TCNT0, TCNT2) are nearly identical. Differences: -TCNT0 can run off an external 32Khz clock (Tosc) or the.
6/21/20151 One-Wire Bus Digital Thermometer Example.
7-Segment Displays Module M7.2 Section 6.5. Turning on an LED Common Anode.
AVR Programming CS-212 Dick Steflik. ATmega328P I/O for our labs To get data into and out of our Arduino its a little trickier than using printf and.
An Embedded C Program 1 Mainly from textbook: Embedded C Programming and the Atmel AVR 2 nd Edition Barnett, Cox and O’Cull.
Embedded Systems Programming 1 ETEE 3285 Topic HW3: Coding, Compiling, Simulating.
UNIT 8 Keypad Interface Contact Closure Counter Exceptions (Interrupts and Reset)
1 4-Integrating Peripherals in Embedded Systems (cont.)
Lecture 9. - Synchronous Devices require a timing signal. Clock generated Interval Timer Microprocessor Interval Timer Clk PCLK = MHz PCLK (for.
KyungHee Univ. 2-0 Parallel Port LED Interfaces. KyungHee Univ. 2-1 Output LEDs.
1 4-Integrating Peripherals in Embedded Systems. 2 Introduction Single-purpose processors  Performs specific computation task  Custom single-purpose.
The miniDragon+ Board and CodeWarrior Lecture L2.1.
Arduino. What is it? A open-source software suite and single-board microcontroller. Allows easy and affordable prototyping of microcontroller applications.
1 Lab 1: Introduction. 2 Configure ATMEL AVR Starter Kit 500 (STK500), a prototyping/development board for Lab1. ATmega16 ( V) is the chip used.
Instrumentation & Control Engg. Section Electrical Engineering Department Ahmedabad , Gujarat.
ECE 371 – Unit 9 Interrupts (continued). Example Set up Two Interrupt Request Inputs: –Port H[0] Set Interrupt Flag on “0” to “1” transition (rising edge)
Serial Communication Interface Ta Kim Nicholas Earnhart Razid Ahmad ME 6405 – Fall 2008 November 6, 2008.
Wall Encounter By Made easy by Dwayne Abuel.
Associative Functions implemented on ClearSpeed CSX600 Mike Yuan.
displayCtrlr Specification
Good LED Circuit 5V0 GND. What Voltage Does Meter See? Answer: 5 V.
Example 11 Analog-to-Digital Converter Lecture L5.1.
Example 12 Pulse-Width Modulation (PWM): Motors and Servos Lecture L8.1.
Projects 8051.
Input Interface – Microprocessor
Programming Microcontrollers in C Lecture L7.1. C Data Types TypeSizeRange char1 byte-128 – 127 unsigned char1 byte0 – 255 Int2 bytes – unsigned.
LHO 22 C and the  The Silicon Labs ISE uses the Keil C51 compiler.  The code size is limiter to 2K  C has replaced PL/M (the original Intel high.
Introduction to Programming Lecture 40. Class Class is a user defined data type.
UNIT 7 - INTRODUCTION TO I/O INTERFACING. TWO MAJOR TYPES OF I/O INTERFACING ISOLATED I/O - DEDICATED I/O INSTRUCTIONS ARE USED TO ACCESS I/O DEVICES.
Arduino libraries Datatekniker Udvidet hardware/software.
EE/CS-352: Embedded Microcontroller Systems Part V The 8051 Assembly Language Interrupts.
Array Sort. Sort Pass 1 Sort Pass 2 Sort Pass 3.
Microcontroller based Traffic signal Umer Butt Amna Rashid Izza Rabbani Rozab Naveed Ramesha Akram.
Tutorial 9 Module 8 – 8.1,8.2,8.3. Question 1 Distinguish between vectored and non-vectored interrupts with an example Build a hardware circuit that can.
Atmega328p Introduction for Digital and PWM Output Brion L Fuller II Robotics Club.
Arduino + Bluetooth TYWu. Connection Arduino + Bluetooth Module.
:Blink Blink: Er. Sahil Khanna
Vishwakarma government engineering college Prepare by. Hardik Jolapara( ) LCD Interfacing with ATmega16.
NAM S.B MDLAB. Electronic Engineering, Kangwon National University 1.
Module 8 Tutorial  An 8086 system is used for controlling the speed of a motor. The motor can operate at 5 different speeds (1- 5).  The speed.
ASSEMBLY CODE EEE 365 [FALL 2014] LECTURE 24 ATANU K SAHA BRAC UNIVERSITY.
Sitarambhai Naranjibhai Patel Institute of Technology and Research Centre, Umrakh, Bardoli. A Presentation On “ 16x2 LCD Interfacing with AVR atmega32.
LCD Interfacing using Atmega 32
4-Integrating Peripherals in Embedded Systems (cont.)
Example 14 Real-time Interrupts
UTA010 : Engineering Design – II
4-Integrating Peripherals in Embedded Systems
Example 19 Measuring Pulse Widths Using Interrupts
4-Integrating Peripherals in Embedded Systems
Example 10 ASCII String to Binary Conversion
Example 5 Pushbutton Switches: S1 and S2
Example 9 Binary to ASCII String Conversion
Example 6 Hex Keypad Lecture L3.2.
Example 15 Interrupt-Driven Controller
Interrupts in C Programs
Example 16 Circular Queue
Example 13 The Serial Peripheral Interface (SPI)
AVR Programming in C Chapter 7
AVR Programming in C Chapter 7
Example 17 SCI Receive Interrupts
Example 7 Liquid Crystal Display
Example 18 Pulse Train Using Interrupts
컴퓨터 프로그래밍 기초 - 13th : 마지막 수업 -
Presentation transcript:

Examples Lecture L2.2

// Example 1a: Turn on every other segment on 7-seg display #include /* common defines and macros */ #include /* derivative information */ #include "main_asm.h" /* interface to the assembly module */ #pragma LINK_INFO DERIVATIVE "mc9s12dp256b" void main(void) { PLL_init(); // set system clock frequency to 24 MHz DDRH = 0xff; // Port H is output PTH = 0x55; // switch on every other segment for(;;) {} /* wait forever */ } Example 1a

// Example 1b: 7-Segment Display #include /* common defines and macros */ #include /* derivative information */ #include "main_asm.h" /* interface to the assembly module */ #pragma LINK_INFO DERIVATIVE "mc9s12dp256b" void main(void) { PLL_init(); // set system clock frequency to 24 MHz seg7_enable(); // enable 7-segment display seg7_on(0x55); // switch on every other segment for(;;) {} /* wait forever */ } Example 1b

Example 1

// Example 2a: Blinking 7-Segment Display #include /* common defines and macros */ #include /* derivative information */ #include "main_asm.h" /* interface to the assembly module */ #pragma LINK_INFO DERIVATIVE "mc9s12dp256b" void delay(void); void main(void) { seg7_enable();// enable 7-segment display while(1){ seg7_on(0xFF);// switch on all segments delay(); seg7_on(0x00);// switch off all segments delay(); } void delay() { int i,j; for(i = 0; i < 500; i++) { for(j = 0; j < 5999; j++) { } Example 2a

// Example 2b: Blinking 7-Segment Display - ms_delay(ms) #include /* common defines and macros */ #include /* derivative information */ #include "main_asm.h" /* interface to the assembly module */ #pragma LINK_INFO DERIVATIVE "mc9s12dp256b" void main(void) { PLL_init(); // set system clock frequency to 24 MHz seg7_enable(); // enable 7-segment display while(1){ seg7_on(0xFF); // switch on all segments ms_delay(500);// half-second delay seg7_on(0x00);// switch off all segments ms_delay(500);// half-second delay } Example 2b

Example 2

// Example 3a: 7-Segment Decoder - C version #include /* common defines and macros */ #include /* derivative information */ #include "main_asm.h" /* interface to the assembly module */ #pragma LINK_INFO DERIVATIVE "mc9s12dp256b" void delay(void); void main(void) { const char seg7tbl[] = { 0x3F,0x06,0x5B,0x4f, 0x66,0x6D,0x7D,0x07, 0x7F,0x6F,0x77,0x7C, 0x39,0x5E,0x79,0x71 }; int i; Example 3a

PLL_init();// set system clock frequency to 24 MHz seg7_enable(); // enable 7-segment display while(1){ for(i = 0; i < 16; i++) { PTH = seg7tbl[i]; delay(); } void delay() { int i,j; for(i = 0; i < 500; i++) { for(j = 0; j < 6248; j++) { } Example 3a (cont.)

// Example 3b: 7-Segment Decoder - seg7dec(i) #include /* common defines and macros */ #include /* derivative information */ #include "main_asm.h" /* interface to the assembly module */ #pragma LINK_INFO DERIVATIVE "mc9s12dp256b" void main(void) { int i; PLL_init();// set system clock frequency to 24 MHz seg7_enable(); // enable 7-segment display while(1){ for(i = 0; i < 16; i++) { seg7dec(i); ms_delay(500); } Example 3b

Example 3

// Example 4a: Single segments in 7-Segment Display #include /* common defines and macros */ #include /* derivative information */ #include "main_asm.h" /* interface to the assembly module */ #pragma LINK_INFO DERIVATIVE "mc9s12dp256b" void delay(void); void main(void) { PLL_init();// set system clock frequency to 24 MHz seg7_enable(); // enable 7-segment display Example 4a

while(1){ PTH |= 0x01; // turn on segment a delay(); PTH |= 0x40; // turn on segment g delay(); PTH |= 0x08; // turn on segment d delay(); PTH &= 0xFE; // turn off segment a delay(); PTH &= 0xBF; // turn off segment g delay(); PTH &= 0xF7; // turn off segment d delay(); } void delay() { int i,j; for(i = 0; i < 500; i++) { for(j = 0; j < 6248; j++) { } Example 4a (cont.)

// Example 4b: Single segments in 7-Segment Display #include /* common defines and macros */ #include /* derivative information */ #include "main_asm.h" /* interface to the assembly module */ #pragma LINK_INFO DERIVATIVE "mc9s12dp256b" void main(void) { /* put your own code here */ seg7_enable(); // enable 7-segment display Example 4b

while(1){ PTH_HI(0); // turn on segment a ms_delay(500);// half-second delay PTH_HI(6); // turn on segment g ms_delay(500);// half-second delay PTH_HI(3); // turn on segment d ms_delay(500);// half-second delay PTH_LO(0); // turn off segment a ms_delay(500);// half-second delay PTH_LO(6); // turn off segment g ms_delay(500);// half-second delay PTH_LO(3); // turn off segment d ms_delay(500);// half-second delay } Example 4b (cont.)

Example 4