Professional Documents
Culture Documents
Centre of Diploma Studies
Centre of Diploma Studies
DEK 3133
MICROCONTROLLER
Experiment Code
03
Experiment Title
Course Code
DET/DEE/DEX
Document Reference
No.
RPP-05
Document Title
LABORATORY
PRACTICUM
Page. Number
Edition
Page |1
1
Revision No.
Effective Date
27/7/2010
Amendment Date
27/7/2010
SUBJECT INFORMATION
SUBJECT
TOPIC
AIM
OBJECTIVES
1.1
1.2
EQUIPMENT
2.1
2.2
2.3
Mikro C
2.4
Proteus
2.5
2.6
Power supply 9V
Document Reference
No.
Document Title
RPP-05
LABORATORY
PRACTICUM
Page. Number
Edition
Page |2
1
Revision No.
Effective Date
27/7/2010
Amendment Date
27/7/2010
THEORY
3.1
Functions
3.2
Conditions
Document Reference
No.
Document Title
RPP-05
LABORATORY
PRACTICUM
Page. Number
Edition
Page |3
1
Revision No.
Effective Date
27/7/2010
Amendment Date
27/7/2010
concurrently with the program. The counter/timer can also be set up to generate an interrupt when it has
reached its maximum value, so that the main program does not have to keep checking it to see if a
particular count has been reached.
3.4
TMR0
o 8 bit TMR0 Module Register
o Count from 0 to 255 (00h to FFh)
INTCON
o GIE - Global Interrupt Enable bit - controls all possible interrupt sources
simultaneously.
1 - Enables all unmasked interrupts.
0 - Disables all interrupts.
o
T0IE - TMR0 Overflow Interrupt Enable bit controls interrupt enabled by TMR0 overflow.
1 - Enables the TMR0 interrupt.
0 - Disables the TMR0 interrupt.
T0IF - TMR0 Overflow Interrupt Flag bit registers the timer TMR0 register overflow, when
counting starts from zero.
1 - TMR0 register has overflowed (bit must be cleared in software).
0 - TMR0 register has not overflowed.
Document Reference
No.
Document Title
RPP-05
LABORATORY
PRACTICUM
Page. Number
Edition
Page |4
1
Revision No.
Effective Date
27/7/2010
Amendment Date
27/7/2010
OPTION
o TOCS Clock Select bit (Bit 5)
1 Pulses are brought to TMR0 timer/counter input through the RA4 pin
0 Internal cycle clock (Fosc/4)
o
PS2
PS1
PS0
TMR0
WDT
1:2
1:1
1:4
1:2
1:8
1:4
1:16
1:8
1:32
1:16
1:64
1:32
1:128
1:64
1:256
1:128
PreparedBy:
Signature:
Name:MohamadBinMd.Som
Date:27July2010
Approvedby:
Signature:
Name:ShamsulB.Mohamad
Date:27July2010
Document Reference
No.
Document Title
LABORATORY
PRACTICUM
Page. Number
Edition
Page |5
1
Revision No.
Effective Date
27/7/2010
Amendment Date
27/7/2010
ATTENTION
4.1
RPP-05
Do not move any IC or device inside the board without any order from your instructor.
EXPERIMENT PROCEDURE
5.1
5.1.1
Circuit 1
Document Reference
No.
Document Title
#define
#define
#define
#define
BUTTON1
BUTTON2
BUTTON3
BUTTON4
RPP-05
LABORATORY
PRACTICUM
Page. Number
Edition
Page |6
1
Revision No.
Effective Date
27/7/2010
Amendment Date
27/7/2010
PORTA.F0
PORTA.F1
PORTA.F2
PORTA.F3
void pattern1(void)
{
PORTB = 0b11111111;
}
void pattern2(void)
{
PORTB = 0b10101010;
}
void pattern3(void)
{
PORTB = 0b11110000;
}
void pattern4(void)
{
PORTB = 0b00001111;
}
void main(void)
{
ADCON1 = 0b00000110; //Set ADCON1 for Port A as a digital input
TRISA = 0b11111111; //Port A as input port
TRISB = 0b00000000; //Port B as output port
PORTB = 0b00000000; //Clear PORTB at start up
while(1) //endless loop
{
if (BUTTON1 == 1) //Test button at PORTA bit 0 if pressed.
pattern1();
//call function pattern1
else if (BUTTON2 == 1)
pattern2();
//call function pattern2
else if (BUTTON3 == 1)
pattern3();
//call function pattern3
else if (BUTTON4 == 1)
pattern4();
//call function pattern4
else
PORTB = 0b00000000; //All LED off if no button pressed
} //end of while (endless loop)
}//end of main func
5.2
Assignment 1.
Base on the Circuit 1, Modify the C code so that each button have a different pattern of animated LEDs. Use 1
second delay for each changing pattern. Test your result in Proteus and put your modifying code in the report.
Document Reference
No.
RPP-05
LABORATORY
PRACTICUM
Document Title
5.3
Page. Number
Edition
Page |7
1
Revision No.
Effective Date
27/7/2010
Amendment Date
27/7/2010
Circuit 2
5.3.1
Baseonthefigureabove(Circuit2),thePICuse4Mhzforitsclockspeed.Writethe
programtoblinktheLEDeveryonesecondbyusingTMR0.Thecodeisshownbelow.
#define
#define
#define
#define
#define
#define
#define
LED1 PORTB.F0
TOCS OPTION_REG.F5
TOSE OPTION_REG.F4
PSA OPTION_REG.F3
PS2 OPTION_REG.F2
PS1 OPTION_REG.F1
PS0 OPTION_REG.F0
Document Reference
No.
Document Title
RPP-05
LABORATORY
PRACTICUM
Page. Number
Edition
Page |8
1
Revision No.
Effective Date
27/7/2010
Amendment Date
27/7/2010
{
overflow++;
TMR0IF = 0;
TMR0IE = 0;
//infinite loop
5.3.2
5.4
5.4.1
Burnthe*.hexfileintoPICandtestthePICatthedevelopmentboard.Writeyour
observationinthereport.
Assignment 2
WriteaCprogramsothattheLEDisblinkingusinghardwaredelaywhichisblinking
every1second.AssumePICclockspeedis1MHzandprescalerusedis1:256.Simulate
yourresultusingProteus.
Document Reference
No.
Document Title
RPP-05
LABORATORY
PRACTICUM
Page. Number
Edition
Page |9
1
Revision No.
Effective Date
27/7/2010
Amendment Date
27/7/2010
(1)
(2)
(3)
(5M)
Observations. (20)
1. Observations from 5.1.1 (Proteus Simulation)
(10 M)
(10 M )
Result. (35)
1. Assignment 1 source code & Flow Chart
( 15 M )
( 20 M )
Discussion. (25)
1. List the Registers related to TMR0 and describes the procedure to setup the TMR0 (15M)
2. If the PIC is supplied with 1 MHz clock speed, calculate time taken for TMR0 to
overflow. Assume that a prescaler 1:256 is used. Show the calculation in your report
(10 M)
Conclusions. (15)