C Examples 1.

Slides:



Advertisements
Similar presentations
Chapter 2 Walking in Circles Programming Loops in C.
Advertisements

Mr. Banyat Somsupan ubonTecnical Unit 2. Electronic Ubontecnical.
Review: Interrupts & Timers
Interrupts, Low Power Modes and Timer A (Chapters 6 & 8)
4-1 Timers Timers can be used for  timing  event counting  pulse width measurement  pulse generation  frequency multiplication There are 8 Timers.
Microcontroller Programming II MP6-1
C HAPTER 2 PIC 16F887 M ICROCONTROLLER Eng. Hazem W. Marar.
C Examples 4.
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.
Mark Neil - Microprocessor Course 1 Timers and Interrupts.
Debouncing Switches Mechanical switches are one of the most common interfaces to a uC. Switch inputs are asynchronous to the uC and are not electrically.
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.
5-1 Timer/Counters In many microprocessor systems we need to:  count logic pulses  measure the frequency of signals  measure the period of pulses 
Timers and Interrupts Shivendu Bhushan Summer Camp ‘13.
Railway Foundation Electronic, Electrical and Processor Engineering.
Lecture 9 Timer Operations and Programming. 2  Introduction  Summary of timers  Timer programming sequence  Summary of timer SFRs  Timer 0: 8-bit.
16-Bit Timer/Counter 1 and 3 Counter/Timer 1,3 (TCNT1, TCNT3) are identical in function. Three separate comparison registers exist. Thus, three separate.
Lecture 9. - Synchronous Devices require a timing signal. Clock generated Interval Timer Microprocessor Interval Timer Clk PCLK = MHz PCLK (for.
ECE 371- Unit 11 Timers and Counters (“Stop Watches and Alarm Clocks”)
7/23 Timers in Coldfire Processor Computer Science & Engineering Department Arizona State University Tempe, AZ Dr. Yann-Hang Lee (480)
V 0.91 Polled IO versus Interrupt Driven IO Polled Input/Output (IO) – processor continually checks IO device to see if it is ready for data transfer –Inefficient,
ARM Timers.
1 4-Integrating Peripherals in Embedded Systems. 2 Introduction Single-purpose processors  Performs specific computation task  Custom single-purpose.
System Clocks.
Introduction to Using MPLAB and Hi-tide Group #9 JoseAlex MikeRoberto Goto and print the file
Chapter 2 A Loop in the Pattern Designing the Main Loop and Timing.
Timers ELEC 330 Digital Systems Engineering Dr. Ron Hayne
CoE3DJ4 Digital Systems Design Chapter 4: Timer operation.
Timers The timers of the PIC16C7X microcontroller can be briefly described in only one sentence. There are three completely independent timers/counters.
MCU: Interrupts and Timers Ganesh Pitchiah. What’s an MCU ?
1 Lab 1: Introduction. 2 Configure ATMEL AVR Starter Kit 500 (STK500), a prototyping/development board for Lab1. ATmega16 ( V) is the chip used.
C Examples 5. Download Links MPLAB IDE dsPIC30F4011/4012 Data Sheet dsPIC30F Family Reference Manual MikroC MikroC Manual MikroC Quick Reference.
ECS642U Embedded Systems Cyclic Execution and Polling William Marsh.
1 68HC11 Timer Chapter HC11 Timer Subsystem Several timing functions: Basic timing Basic timing Real time interrupts Real time interrupts Output.
Timers and Interrupts Anurag Dwivedi. Let Us Revise.
Conclusion Speech. Content Organization Pronunciation Handwriting.
Saxion University of Applied Sciences Advanced Microcontrollers A practical approach.
Interrupts  An interrupt is any service request that causes the CPU to stop its current execution stream and to execute an instruction stream that services.
DsPIC30F4011 Fall DIP Switches  The upper four switches of SW1 are used to enable LEDs connected to PORTB/C, PORTA/D, PORTE and PORTF. For example,
© 2009, Renesas Technology America, Inc., All Rights Reserved 1 Course Introduction  Purpose This course provides an introduction to the peripheral functions.
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.
C Examples 1. Download Links MPLAB IDE dsPIC30F4011/4012 Data Sheet dsPIC30F Family Reference Manual MikroC MikroC Manual MikroC Quick Reference.
Interrupt On a very basic level, an interrupt is a signal that interrupts the current processor activity. It may be triggered by an external event (change.
The Silicon Laboratories C8051F020
C Examples 1. Download Links dsPIC30F4011/4012 Data Sheet dsPIC30F4013/3014 dsPIC30F Family Reference Manual MikroC MikroC Manual MikroC Quick Reference.
Lecture 4 General-Purpose Input/Output NCHUEE 720A Lab Prof. Jichiang Tsai.
EE/CS-352: Embedded Microcontroller Systems Part V The 8051 Assembly Language Interrupts.
PIC16F887.
C Examples 6. Download Links MPLAB IDE dsPIC30F4011/4012 Data Sheet dsPIC30F Family Reference Manual MikroC MikroC Manual MikroC Quick Reference.
Embedded Programming and Robotics Lesson 11 Arduino Interrupts 1.
1 68HC11 Timer. 2 68HC11 Timer Subsystem Several timing functions: Basic timing Basic timing Real time interrupts Real time interrupts Output compare.
Timer & Watch Dog Test UNIT 16 로봇 SW 교육원 조용수. 학습 목표 Timer Init Timer Delay Test Timer Interrupt Test –One Shot Mode –Periodic Mode Watch Dog Test 시계 만들어.
Microcontrollers JULES CALELLA. Microcontrollers vs Microprocessors  Microprocessors – do not contain RAM, ROM, I/O  Microcontrollers – The whole package.
One more PIC18F252 example and revision for exam B222L Branislav Vuksanovic, UoP, ECE.
Microprocessors A practical approach..
TIMERS.
C Examples 3. Download Links dsPIC30F4011/4012 Data Sheet dsPIC30F4013/3014 dsPIC30F Family Reference Manual MikroC MikroC Manual MikroC Quick Reference.
C Examples 3. Download Links dsPIC30F4011/4012 Data Sheet dsPIC30F4013/3014 dsPIC30F Family Reference Manual MikroC MikroC Manual MikroC Quick Reference.
Why are Timer Functions Important?
Timer and Interrupts.
RX 8-Bit Timer (TMR) 4/20/2011 Rev. 1.00
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.
The Arduino Microcontroller: Atmel AVR Atmega 328
Timer/Counter Modified from Dr. Lam Phung’s Slides.
ATmega103 Timer0 and Interrupts
전자의료시스템 및 실습 System Configuration/Interrupt
EECE.3170 Microprocessor Systems Design I
EECE.3170 Microprocessor Systems Design I
Presentation transcript:

C Examples 1

Download Links MPLAB IDE dsPIC30F4011/4012 Data Sheet dsPIC30F Family Reference Manual MikroC MikroC Manual MikroC Quick Reference

LED ON main () { TRISB=0b11111101; while(1) PORTB.F1=1; }

Blinking LED - 1 main () { ADPCFG = 0xFFFF; TRISB=0b11111101; PORTB.F1=1; while(1) Delay_ms(1000); PORTB.F1=PORTB.F1^1; }

Blinking LED - 2 main () { ADPCFG = 0xFFFF; TRISB=0b11111101; PORTB.F1=1; while(1) Delay_ms(1000); PORTB=PORTB^0x02; }

Timer 1 16-bit Timer Mode: In the 16-bit Timer mode, the timer increments on every instruction cycle up to a match value, preloaded into the Period register, PR1, then resets to 0 and continues to count. When the CPU goes into the Idle mode, the timer will stop incrementing unless the TSIDL (T1CON<13>) bit 0. If TSIDL 1, the timer module logic will resume the incrementing sequence upon termination of the CPU Idle mode. 16-bit Synchronous Counter Mode: In the 16-bit Synchronous Counter mode, the timer increments on the rising edge of the applied external clock signal, which is synchronized with the internal phase clocks. The timer counts up to a match value preloaded in PR1, then resets to 0 and continues. When the CPU goes into the Idle mode, the timer will stop incrementing unless the respective TSIDL bit o. If TSIDL 1, the timer module logic will resume the incrementing sequence upon termination of the CPU Idle mode.

Blinking LED - 3 main () { T2CON=0x8030; // Enable Timer 2 Prescaler=256 IEC0=0x0040; // Enable Interrupt for Timer 2 PR2=0xFFFF; ADPCFG = 0xFFFF; TRISB=0b11111101; PORTB=PORTB|0b00000010; while(1) } void interrupt_T2() org 0x000020 PORTB=PORTB^0x02; IFS0=0x0000;

Blinking LED - 3 main () { T2CON=0b1000000000001000; // Enable Timer 2/3 IEC0=0x0080; // Enable Interrupt for Timer 3 PR2=0xFFFF; PR3=0x0AFF; ADPCFG = 0xFFFF; TRISB=0b11111101; PORTB=0x00; while(1) } void interrupt_T2() org 0x000022 PORTB=PORTB^0x02; IFS0=0x0000;

Switch + LED main () { ADPCFG = 0xFFFF; TRISB=0b11111101; TRISE=0b000001; PORTB=0x00; PORTE=0x1F; while(1) if((PORTE&0b000001)==0) {PORTE.F1=PORTE.F1^1;} }

Key DEBOUNCING - 1 main () { int i; const int Twentyms = 4210; ADPCFG = 0xFFFF; TRISB=0b11111101; TRISE=0b000001; PORTB=0x00; PORTE=0x1F; while(1) i = 0; // Wait 20 ms for Button Up while (i < Twentyms) if (0 == PORTE.F0) // Button Down/Start over i = 0; } else // Button Up/Increment Count i = i + 1; } // i = 0; // Wait 20 ms for Button Down if (1 == PORTE.F0) // Button Up/Start over else // Button Down/Increment Count PORTE.F1=PORTE.F1^1; // Toggle LED to Turn ON/OFF LED

Key DEBOUNCING - 2 int function_key(void) { int i,m; const int Twentyms = 4210; m=1; if (1 == PORTE.F0) {return(m);} while(1) i = 0; // Wait 20 ms for Button Up while (i < Twentyms) if (0 == PORTE.F0) // Button Down/Start over i = 0; } else // Button Up/Increment Count i = i + 1; } // i = 0; // Wait 20 ms for Button Down if (1 == PORTE.F0) // Button Up/Start over else // Button Down/Increment Count m=0; // Toggle LED to Turn ON/OFF LED return(m);

Key DEBOUNCING - 2 main () { int s=1; ADPCFG = 0xFFFF; TRISB=0b11111101; PORTB=0x00; TRISE=0b000001; PORTE=0x1F; while(1) s=function_key(); if (s==0) PORTE.F1=PORTE.F1^1; S=1; }

Key DEBOUNCING - 3 main () { int s=1; ADPCFG = 0xFFFF; TRISB=0b11111101; PORTB=0x00; TRISE=0b000001; PORTE=0x1F; while(1) Delay_ms(5000); PORTB=~PORTB; s=function_key(); if (s==0) PORTE.F1=PORTE.F1^1; S=1; }

Key DEBOUNCING - 4 main () { int s=1; T2CON=0x8030; // Enable Timer 2 Prescaler=256 IEC0=0x0040; // Enable Interrupt for Timer 2 PR2=0xFFFF; ADPCFG = 0xFFFF; TRISB=0b11111101; PORTB=0x00; TRISE=0b000001; PORTE=0x1F; while(1) s=function_key(); if (s==0) PORTE.F1=PORTE.F1^1; S=1; } void interrupt_T2() org 0x000020 PORTB=PORTB^0x02; IFS0=0x0000;

UART1

UART1 unsigned rx1; unsigned char uc1; void main() { Uart1_Init(19200); U1MODE = 0x8400; delay_ms(200); TRISE=0b000001; PORTE=0x1F; Uart1_Write_Char('a'); while(1) { if (Uart1_Data_Ready()) { rx1 = Uart1_Read_Char(); Uart1_Write_Char(++rx1); PORTE=~PORTE; } }//~!

UART2 unsigned rx1; unsigned adcRes; unsigned char uc1; void main() { PORTB = 0x0000; TRISB = 0xFFFF; Uart1_Init(19200); U1MODE = 0x8400; delay_ms(200); TRISE=0b000001; PORTE=0x1F; Uart1_Write_Char('a'); while(1) { adcRes = Adc_Read(3); Uart1_Write_Char(adcRes); PORTE=~PORTE; delay_ms(1000); } }//~!