Вы находитесь на странице: 1из 15

Adeel Pasha, LUMS, 2014-15

Lab-1: PICC-based Labs


Timers, Interrupts and RTOS APIs

Adeel Pasha, LUMS, 2014-15

Features of PIC 18F452


RISC-based processor
Operating frequency up to (48MHz)*
32-35 GPIOs
3 Timers (T0, T1, T2)
Internal 10-bit ADC
USART
2.0V to 5.0V working range+
* 20MHz mentioned in Datasheet
+ Depends on X in18X452
2

EE-522

2/9/2016

Adeel Pasha, LUMS, 2014-15

Compiler
We will be using CCS PICC
Built-in RTOS library
Has a time-driven (variant of cyclic) scheduler for RT-task

scheduling
Supports multi-tasking and delay functions
Non-preemptive scheduler in nature
User friendly
Built-in functions for I/Os
Support for standard C functions e.g. printf , scanf , etc.

Interaction with hyper-terminals through RS-232 port

EE-522

2/9/2016

Adeel Pasha, LUMS, 2014-15

Example: I/O Functions


output_b(255);

//TurnsallPINSonPortBhigh

output_low(PIN_B5);

//OnlyPIN5ofPortBwillbehigh

output_high(PIN_B4);

//OnlyPIN4ofPortBwillbelow

output_toggle(PIN_B3);

//TogglePIN3ofPortB

input_b();

//TurnsPortBasinputandreturnscomplete
//1byteofdatavaluestoredatPortB

input(PIN_B7);

EE-522

//TurnsPIN7ofPORTBasinputandreturns
//singlebiti.e.1ifitishighelse0

2/9/2016

Adeel Pasha, LUMS, 2014-15

Example: Testing I/O Ports


while(TRUE){
output_b(255);

//turnallpinsofportBON

output_d(255);

//turnallpinsofportBON

delay_ms(500);

//introduceadelayof500ms

output_b(0);

//turnallpinsofportBON

output_d(0);

//turnallpinsofportBON

delay_ms(500);
//printHelloWorldtooutputdevice(serialport)
printf("HelloWorld\n\r");
}

EE-522

2/9/2016

Adeel Pasha, LUMS, 2014-15

Example: Interrupt Handler in PIC


#INT_XXXX
//definesinterruptroutine
voidXXXX_isr(){
[ISRRoutineforInterruptXXXX]
.
.
}
.
.
.
void main(){
.
.
enable_interrupts(INT_XXXX);
//enablesXXXXinterrupt
enable_interrupts(GLOBAL);
//enablesglobalinterrupts
.
//enablespreviousinterruptstobecomeactive
.
}

EE-522

2/9/2016

Adeel Pasha, LUMS, 2014-15

Softwares Needed
PIC-C Programming Environment
MikroProg Suite to program the PIC18F452
Hyper Terminal for serial output on Windows
Make sure all of them are installed on the PC where you are working
If not get them from the TAs

Run all those SWs as administrator


Dont login using your ID, use EELAB ID
7

EE-522

2/9/2016

Adeel Pasha, LUMS, 2014-15

SWs Needed

EE-522

2/9/2016

Lab-1 Manual

EE-522

2/9/2016

Adeel Pasha, LUMS, 2014-15

PICC-RTOS API
# use rtos (options)
timer
minor_cycle
statistics

# task (options)
rate
max

rtos_run()
rtos_terminate()
rtos_enable(task)
rtos_disable(task)
10

EE-522

rtos_stats()
rtos_overrun()
rtos_await (expression)
rtos_wait(semaphore)
rtos_signal(semaphore)
rtos_yield ()

2/9/2016

Adeel Pasha, LUMS, 2014-15

Example: Testing I/O Ports using RTOS


#usertos(timer=1,minor_cycle=100ms)
intout;
#task(rate=500ms,max=50ms)
voidLED_Blink(){
out=~out;
output_b(out);
output_d(out);
}
#task(rate=1000ms,max=50ms)
voidSERIAL_Write(){
printf("HelloWorld\n\r");
}

11

EE-522

voidmain()
{
out=0xFF;
rtos_run();
sleep();
}

2/9/2016

Adeel Pasha, LUMS, 2014-15

PICC-RTOS Scheduler Semantics


main()

rtos_run()

rtos_terminate

RTOS
Time Period 1

Time Period 2

return/wait
TASK1

12

EE-522

TASK2

2/9/2016

Lab-1 Manual

13

EE-522

2/9/2016

Adeel Pasha, LUMS, 2014-15

EE-522 Term Schedule


W1:19/1
Intro

W1:21/1
RT-Scheduling

W2:26/1
Static Scheduling
Algos

W2:28/1
Dynamic Scheduling
Algos-I

W3:02/2
Dynamic + PriorityDriven Schedulers

W3:04/2
Mem-mapped IOs,
GPIOs etc.

W4:09/2
Lab1
(PIC-based)

W4:11/2
Lab2
(PIC-based)

W5:16/2
Commercial RTOS

W5:18/2
Linux Device
Drivers

W6:23/2
Lab3
(VM-Linux Kernel)

W6:25/2
Commercial RTOS

W7: 01/3
Resource Sharing

W7:03/3
Resource Sharing in
MP

W8:08/3
Lab4
(Mini6410-based)

W8:10/3
Mid term

W9:22/3
Lab5
(Mini6410-based)

W9:24/3
RT Comm.

W10:29/3
RT Comm. II

W10:31/3
Lab6
(Mini6410-based)

W11:05/4
Lab7
(Mini6410-based)

W11:07/4
RT Databases

W12:12/4
Lab8
(Mini6410-based)

W12:14/4
Lab9
(Mini6410-based)

W13:19/4
Lab10
(Mini6410-based)

W13:21/4
Lab11
(Mini6410-based)

W14:26/4
Lab12
(Lab Project)

W14:28/4
Lab13
(Lab Project)

W15:03/5
RT Databases

W15:05/5
Lab14
(Lab Project Demo)

14

EE-522

2/9/2016

Deadline for Lab-1 Assignments


Thursday Feb 11, 2016 5:00pm
(But at least complete assignment-1 and 2 today)

15

EE-522

2/9/2016

Вам также может понравиться