Lecture 3 C Programming For PICs
Lecture 3 C Programming For PICs
Programming for
PICs
Mikro C Programming Language
• It is a C programming language modified and
customised to suit development of programs for
Microchip PICs.
• Same syntax
• Also borrows some C++ syntax.
• Assignment operator: =
TMR0 = 58;
• Operations: +, -, *, /, etc.
WEIGHT = ADRESL/4;
• The file register containing the bit and the bit position
are specified, separated by a decimal point.
• For example INTCON.GIE, PIR1.B7, mask.b3,
PORTB.B7.
• INTCON.GIE = 1;
• PIR1.B7 = 0;
• Mask.b3 = 1;
• RB3_bit = 0;
• RP0_bit = 1;
Accessing Bits in File Registers
Example to check port pins
if (RA2_bit == 0)
{
// put code here
}
else
{
// put alternate code here
}
The sbit Variable
• The sbit data type provides access to SFRs, bits, variables,
etc.
LOOP
Set port pins high
Delay 1s
Delay 1s
void main() {
void main() {
TRISA = 0x00;
TRISB = 0x00;
TRISC = 0x00;
TRISD = 0x00;
TRISE = 0x00;
do {
PORTA = 0x00;
PORTB = 0x00;
PORTC = 0x00;
PORTD = 0x00;
PORTE = 0x00;
Built-in Routines
• The Mikro C compiler provides a set of useful built-in
utility functions.
•Questions 1
•Question 2