Professional Documents
Culture Documents
2015 - 16 - Lecture For RTS Laboratory 2
2015 - 16 - Lecture For RTS Laboratory 2
Todays material
Looking at PICs (in general)
Getting a working system
However
A reset MCLR
You may sacrifice this is the pin doubles up for a
function you require more
http://circuit-zone.com/ediy_blog/190/PIC12F675_Flashing_Blinking_LED.jpg
The overview
The Peripherals
The audio
How do we so do this?
The first task is to indicate how the pin is to
work (will it be an input or an output_
This is done using the TRIS (Tristate)
register for the port
RA6
RA5
RA4
RA3
RA2
RA1
RA0
128
64
32
16
b0000111
TRISA
Note:
We would not need to define TRISA as the
selection of device would provide this to the
compiler
So how do I do this in C
// All output
Then
PORTA = 0b10101010;
Latches alternate pins at 5v, 0v, 5v etc. (if
Vdd=5v)
Reading in
We can read the value across the pins and store this in
a suitable variable
So, if we had set
Then
Connect 5v (Vdd) to pins RA0,1,2,3
// Turn it on
// Turn it off
Note
The above are defined in code for ease of use (see below)
#define _TRISA0 TRISAbits.TRISA0
#define _RA0
PORTAbits.RA0
A reminder from C
A new bit of C
UNIONS
union DataUnion
{
int a,b;
float c,d;
};
This is a technique in C
where we allow variables to
SHARE memory
int main(void)
{
union DataUnion DU;
DU.a = 1;
printf ("\nDU.a = %d ", DU.a);
printf ("\nDU.b = %d ", DU.b);
DU.b = 2;
printf ("\nDU.a = %d ", DU.a);
printf ("\nDU.b = %d ", DU.b);
return 0;
}
UNIONS in action
union DataUnion
{
int a,b;
float c,d;
};
int main(void)
{
union DataUnion DU;
DU.a = 1;
printf ("\nDU.a = %d ",
printf ("\nDU.b = %d ",
DU.b = 2;
printf ("\nDU.a = %d ",
printf ("\nDU.b = %d ",
return 0;
}
DU.a);
DU.b);
DU.a);
DU.b);
Output (PC)
Consider
:1;
TCS:1;
TSYNC:1;
:1;
TCKPS:2;
TGATE:1;
:6;
TSIDL:1;
:1;
TON:1;
We can then
Set the whole register in one
go
T1CON = 0x5066;
Your tasks
Are to use these to display information on the
screen (numbers)
To build a little egg timer
We dig deeper
Look how the CheckSwitchS1/2 functions work
Consider techniques including
Polling
Interrupts
Timers
And (alas)
I have to let you use global variables
But in a very controlled manner!