C:\Users\cunningh\StaysOnPC\ME430 Downloads & Projects\exam2_problem1\problem1Cunningham.c

Similar documents
Human Response Timer

Accurate Time and Interrupts

Interrupts on PIC18F252 Part 2

Analog Output with a Digital to Analog Converter

The MCU s Pulse. Internal clock or oscillator to synchronize operation. One clock cycle = 1 TOSC = 1/fOSC. t TOSC

Capture Mode of Pic18F252

Implementation of Temperature Sensor on PICM4520 Microcontroller

Internet de les coses aplicat a la millora del servei de Bicing de Barcelona Pàg. 1

Interrupts on PIC18F252 Part 2. Interrupts Programming in C Language

BME 361 Biomeasurement Laboratory Demonstration Biomedical Engineering Program University of Rhode Island June 10, 2015

Timer0..Timer3. Interrupt Description Input Conditions Enable Flag

unsigned char ReadADC() { /************* start A/D, read from an A/D channel *****************/ unsigned char ADC_VALUE;

Microchip 18F4550 Interface, Signal conditioning, USB, USB- RS-232, 16x2 LCD Interface

Speed Control of a DC Motor using Digital Control

Project Number: RF Project Description: Appendix:

Embedded Systems Module. 6EJ505. C Tutorial 3: using the ICD3 rev tjw

Embedded systems. Exercise session 3. Microcontroller Programming Lab Preparation

unsigned char ReadADC() { /************* start A/D, read from an A/D channel *****************/ unsigned char ADC_VALUE;

Topic 10 10/24/2010. C with Embedded Extension

Timer 32. Last updated 8/7/18

Timer2 Interrupts. NDSU Timer2 Interrupts September 20, Background:

Remote Controlled KitchenAid Mixer for the Clients at ADEC. Appendices. Arnaud Bacye Karina Dubé Justin Erman Matthew Martin

Timer1 Capture Mode:

Application Note One Wire Digital Output. 1 Introduction. 2 Electrical Parameters for One Wire Interface. 3 Start and Data Transmission

/*Algorithm: This code display a centrifuge with five variable speed RPM by increaseing */

Lecture (03) PIC16F84 (2)

ECE Homework #10

MPLAB C1X Quick Reference Card

Problem Score 1 / 10 2 / 26 3A / 10 3B / 12 3C / 6 4 / code check off / 22 /2 Total /100

EE 361L Digital Systems and Computer Design Laboratory

C and Embedded Systems. So Why Learn Assembly Language? C Compilation. PICC Lite C Compiler. PICC Lite C Optimization Results (Lab #13)

Lecture (04) PIC 16F84A programming I

ELCT 912: Advanced Embedded Systems

ECE2049: Embedded Computing in Engineering Design C Term Spring Lecture #11: More Clocks and Timers

The University of Texas at Arlington Lecture 5

Table of Figures Figure 1. High resolution PWM based DAC...2 Figure 2. Connecting the high resolution buck converter...8

Flow Charts and Assembler Programs

Programmable Pet Feeder

Microchip Corporate Applications, Aug 2005 Dennis Lehman, Corporate Applications Engineer

By the end of Class. Outline. Homework 5. C8051F020 Block Diagram (pg 18) Pseudo-code for Lab 1-2 due as part of prelab

Interrupts. Embedded Systems Interfacing. 08 September 2011

Laboratory 10. Programming a PIC Microcontroller - Part II

Hong Kong Institute of Vocational Education Digital Electronics & Microcontroller. 8. Microcontroller

Chapter 9. Input/Output (I/O) Ports and Interfacing. Updated: 3/13/12

MicroToys Guide: PS/2 Mouse N. Pinckney April 2005

Final Design Report 19 April Project Title: Pneumatic Exercise Machine

LCD. Configuration and Programming

1 Introduction to Computers and Computer Terminology Programs Memory Processor Data Sheet Example Application...

Interrupt vectors for the 68HC912B32. The interrupt vectors for the MC9S12DP256 are located in memory from 0xFF80 to 0xFFFF.

Lecture (09) PIC16F84A LCD interface LCD. Dr. Ahmed M. ElShafee

Dept. of Computer Engineering Final Exam, First Semester: 2016/2017

Embedded Systems Programming and Architectures

The modules in this lab room are 4 line by 16 character display modules. The data sheet/users manual for the module is posted on My.Seneca.

BME 4900 Page 1 of 2. Meeting 2: Personal Progress Report 12/2/09 Team 12 with Drew Seils. Semester One Week Two

GPS Reader. Figure 1: RMC NEMA Tag Definition

1 Introduction to Computers and Computer Terminology Programs Memory Processor Data Sheet... 4

EE Embedded Systems Design. Lessons Exceptions - Resets and Interrupts

Microcontroller Overview

Chapter 11: Interrupt On Change

UNCA CSCI 255 Exam 3 Fall 2011

SOLUTIONS!! DO NOT DISTRIBUTE PRIOR TO EXAM!!

LAB WORK 2. 1) Debugger-Select Tool-MPLAB SIM View-Program Memory Trace the program by F7 button. Lab Work

ADC: Analog to Digital Conversion

Development Hardware. Target Board and In-circuit Debugger

University of Jordan Faculty of Engineering and Technology Department of Computer Engineering Embedded Systems Laboratory

Fujitsu Microelectronics Europe Application Note MCU-AN E-V10 FR FAMILY 32-BIT MICROCONTROLLER MB91460 REAL TIME CLOCK APPLICATION NOTE

Introduction to the MC9S12 Hardware Subsystems

University of Texas at El Paso Electrical and Computer Engineering Department. EE 3176 Laboratory for Microprocessors I.

EET203 MICROCONTROLLER SYSTEMS DESIGN Serial Port Interfacing

dspic Interrupts The Interrupt Control and Staus Registers are :- ENG721-S2 Mixed Signal Processing : Hassan Parchizadeh Page 1

ECE PRACTICE EXAM #2 Clocks, Timers, and Digital I/O

MPLAB SIM. MPLAB IDE Software Simulation Engine Microchip Technology Incorporated MPLAB SIM Software Simulation Engine

Microprocessors B Lab 1 Spring The PIC24HJ32GP202

The MC9S12 Timer Output Compare Function Making an event happen at specific time on the HC12 The MC9S12 Output Compare Function

Capturing the Time of an External Event Input Capture Subsystem

DEV-1 HamStack Development Board

CPE 325: Embedded Systems Laboratory Laboratory #7 Tutorial MSP430 Timers, Watchdog Timer, Timers A and B

C Language Programming, Interrupts and Timer Hardware

LCDs. Embedded Systems Interfacing. 20 September 2011


SquareWear Programming Reference 1.0 Oct 10, 2012

C Programming Language

Example of Asyncronous Serial Comms on a PIC16F877

What happens when an HC12 gets in unmasked interrupt:

ME 6405 Introduction to Mechatronics

Simple cpik Tutorial

University of Hawaii EE 361L MPLab Quick Tutorial and Project 2.1 Last updated September 1, 2011

A simple data logger for student-designed rocket experiments.

EE 308 Spring Exam 1 Feb. 27

LAMPIRAN. 1. Program Alat

CHAPTER 1 - World of microcontrollers

These 3 registers contain enable, priority,

EE4390 Microprocessors

F²MC-8FX FAMILY MB95200H/210H SERIES HOW TO USE DBG PIN 8-BIT MICROCONTROLLER APPLICATION NOTE

Introduction to Microcontroller Apps for Amateur Radio Projects Using the HamStack Platform.

The MC9S12 Timer Input Capture Function

e-pg Pathshala Subject: Computer Science Paper: Embedded System Module: Interrupt Programming in Embedded C Module No: CS/ES/20 Quadrant 1 e-text

F²MC-8FX FAMILY MB95200H/210H SERIES HOW TO USE DBG PIN 8-BIT MICROCONTROLLER APPLICATION NOTE

Interrupts & Interrupt Service Routines (ISRs)

Embedded Systems. October 2, 2017

Transcription:

C:\Users\cunningh\StaysOnPC\ME430 Downloads & Projects\exam2_problem1\problem1Cunningham.c / FileName: problem1cunningham.c Processor: PIC18F4520 Compiler: MPLAB C18 v.3.06 This file does the following... Creation and Revisions: Author Date Comments Patrick Cunningham 10/21/2011 / / Header Files / #include <p18f4520.h> #include <adc.h> / Configuration Bits / #pragma config OSC = EC // EC = External 4MHz Crystal for PICDEM board only #pragma config WDT = OFF #pragma config LVP = OFF #pragma config BOREN = OFF #pragma config XINST = OFF / Define Constants Here / #define SAMPLE 100 / Local Function Prototypes / void samplefunction(void); / Global Variables / int samplevariable = 0; int RA0result; / Function: void main(void) / #pragma code void main (void) ADCON1 = 0x0E; // Set RA0 to Analog, not necessary here TRISB = 0x00; // Set PortB to outputs PORTB = 0x00; // Initalize PortB so LEDs are off // Configure the A/D convertor OpenADC( ADC_FOSC_8 & ADC_RIGHT_JUST & ADC_12_TAD, ADC_CH0 & ADC_INT_OFF & ADC_REF_VDD_VSS, 0x0E ); while (1) 1

C:\Users\cunningh\StaysOnPC\ME430 Downloads & Projects\exam2_problem1\problem1Cunningham.c SetChanADC(ADC_CH0); // Not necessary here ConvertADC(); while( BusyADC() ); RA0result = ReadADC(); if( RA0result <= 250 ) PORTB = 0b00001000; else if ( (RA0result > 250) && (RA0result <= 550) ) PORTB = 0b00001100; else if ( (RA0result > 550) && (RA0result <= 800) ) PORTB = 0b00001110; else PORTB = 0b00001111; / Additional Helper Functions / / Function: void sample(void) Input Variables: none Output Return: none Overview: Use a comment block like this before functions / void samplefunction() // Some function that does a specific task 2

C:\Users\cunningh\StaysOnPC\ME430 Downloads & Projects\exam2_problem2\problem2Cunningham.c / FileName: (change filename of template).c Processor: PIC18F4520 Compiler: MPLAB C18 v.3.06 This file does the following... Author Date Comment ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~/ // (Your name here) / Header Files / #include <p18f4520.h> #include <portb.h> #include <timers.h> #include <pwm.h> #include <delays.h> / Configuration Bits / #pragma config OSC = EC // EC = External 4MHz Crystal for PICDEM board only #pragma config WDT = OFF #pragma config LVP = OFF #pragma config BOREN = OFF #pragma config XINST = OFF / Define Constants Here / #define SAMPLE 100 / Local Function Prototypes / void low_isr(void); void high_isr(void); void samplefunction(void); / Declare Interrupt Vector Sections / #pragma code high_vector=0x08 void interrupt_at_high_vector(void) _asm goto high_isr _endasm #pragma code low_vector=0x18 void interrupt_at_low_vector(void) _asm goto low_isr _endasm / Global Variables / int samplevariable = 0; unsigned char PWMperiod[] = 141, 119, 105, 94, 79, 70 ; char idx = 0; 1

C:\Users\cunningh\StaysOnPC\ME430 Downloads & Projects\exam2_problem2\problem2Cunningham.c / Function: void main(void) / #pragma code void main (void) ADCON1 = 0x0F; // set all pins to digital TRISB = 0x01; // set RB0-RB3 to inputs RCONbits.IPEN = 0; // interrupts in compatibility mode // Configure RB0 Interrupts OpenRB0INT( PORTB_CHANGE_INT_ON & FALLING_EDGE_INT & PORTB_PULLUPS_OFF ); INTCONbits.GIE = 1; // enable global interrupts // Configure Timer 2 for PWM functionality OpenTimer2( TIMER_INT_OFF & T2_PS_1_16 ); while (1) // This area loops forever / Additional Helper Functions / / Function: void sample(void) Input Variables: none Output Return: none Overview: Use a comment block like this before functions / void samplefunction() // Some function that does a specific task / Function: void high_isr(void) Possible sources of interrupt - none Overview: / #pragma interrupt high_isr void high_isr(void) if( INTCONbits.INT0IF ) INTCONbits.INT0IF = 0; OpenPWM1(PWMperiod[idx]); // 440 Hz A4 2

C:\Users\cunningh\StaysOnPC\ME430 Downloads & Projects\exam2_problem2\problem2Cunningham.c // SetDCPWM1(102); // 10% Duty Cycle // Delay10KTCYx(100); // Wait 1 second // SetDCPWM1(0); // Turn Buzzer on while RB0 is pressed while( PORTBbits.RB0 == 0 ) SetDCPWM1(102); // 10% Duty Cycle SetDCPWM1(0); // Turn Buzzer off idx++; if( idx == 6 ) idx = 0; / Function: void low_isr(void) Possible sources of interrupt - none Overview: / #pragma interruptlow low_isr void low_isr(void) // Add code here for the low priority Interrupt Service Routine (ISR) 3

C:\Users\cunningh\StaysOnPC\ME430 Downloads & Projects\exam2_problem3\problem3Cunningham.c / FileName: (change filename of template).c Processor: PIC18F4520 Compiler: MPLAB C18 v.3.06 This file does the following... Author Date Comment ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~/ // (Your name here) / Header Files / #include <p18f4520.h> #include <stdio.h> #include <timers.h> #include "LCD Module.h" / Configuration Bits / #pragma config OSC = EC // EC = External 4MHz Crystal for PICDEM board only #pragma config WDT = OFF #pragma config LVP = OFF #pragma config BOREN = OFF #pragma config XINST = OFF / Define Constants Here / #define SAMPLE 100 / Local Function Prototypes / void low_isr(void); void high_isr(void); void samplefunction(void); void updatelcd(void); / Declare Interrupt Vector Sections / #pragma code high_vector=0x08 void interrupt_at_high_vector(void) _asm goto high_isr _endasm #pragma code low_vector=0x18 void interrupt_at_low_vector(void) _asm goto low_isr _endasm / Global Variables / int samplevariable = 0; char LCD_str[17]; unsigned int idx = 1; 1

C:\Users\cunningh\StaysOnPC\ME430 Downloads & Projects\exam2_problem3\problem3Cunningham.c unsigned int Fcurr; unsigned int tmrstart = 34285; / Function: void main(void) / #pragma code void main (void) TRISD = 0x00; // Make all D Channels Outputs (for LCD) XLCDInit(); XLCDClear(); // Initialize & Clear the LCD Display RCONbits.IPEN = 0; // Interrupts in Compatibility Mode // Configure Timer0 OpenTimer0( TIMER_INT_ON & T0_16BIT & T0_SOURCE_INT & T0_PS_1_16 ); INTCONbits.GIE = 1; // Enable Global Interrupts WriteTimer0(tmrStart); // while (1) // This area loops forever / Additional Helper Functions / / Function: void sample(void) Input Variables: none Output Return: none Overview: Use a comment block like this before functions / void samplefunction() // Some function that does a specific task / Function: void updatelcd(void) Input Variables: Output return: Overview: When called, updates the LCD with the latest age global variables. / void updatelcd(void) // Go to the start of line 1 2

C:\Users\cunningh\StaysOnPC\ME430 Downloads & Projects\exam2_problem3\problem3Cunningham.c // write line 1 XLCDL1home(); XLCDPutRamString(LCD_str); / Function: void high_isr(void) Possible sources of interrupt - none Overview: / #pragma interrupt high_isr void high_isr(void) if( INTCONbits.TMR0IF ) INTCONbits.TMR0IF = 0; // Reset Interrupt Flag Fcurr = idxidxidx; // Compute n^3 sprintf(lcd_str,"f( %-u) = %-u", idx, Fcurr); updatelcd(); idx++; // Increment Counter WriteTimer0(tmrStart); / Function: void low_isr(void) Possible sources of interrupt - none Overview: / #pragma interruptlow low_isr void low_isr(void) // Add code here for the low priority Interrupt Service Routine (ISR) 3