Support from the University of Birmingham for Legal Council
ENGINEERING AND COMPUTER WORKS
Block 738, #12-373, Woodlands Circle, Singapore 730738;
Level 28, PJ Exchange, No. 16A, Persiaran Barat, 46050 Petaling Jaya, Selangor Darul Ehsan, Kuala Lumpur, Malaysia
ph: +65 9173 7839(Singapore) ; +6017 396 7471(Malaysia)
fax: +65 63680320 (Singapore) ;
alt: +1 (503) 928 7953 ;
chanjunt
MICROCHIP LIGHTING A LED
The program below is utilized to switch an Input and Output on and off and can be made
to light LEDs higher than 5V.
*/
#asm
List p=16f84a
__config h'3ff1'
Radix hex
#endasm
int i, j;
main()
{
PORTA = 0x3F; // All Bits are High
CMCON0 = 7; // Turn off Comparators
ANSEL = 0; // Turn off ADC
TRISA4 = 0; // Make RA4/RA5 Outputs
TRISA5 = 0;
while(1 == 1) // Loop Forever
{
if (0 == RA3) // Set values using "if" statement
{
RA5 = 0;
}
else
{
RA5 = 1;
} // fi
} // elihw
} // End cButton
The program sets a LED on and off.
The schematics is as follows:
___________________________________________________________________________
Running LED
The circuit comprises of assembly language programming and is utilized as a
running LED.
The LED values are:
LED Anode Cathode
D0 RA4 RA5
D1 RA5 RA4
D2 RA4 RA2
D3 RA2 RA4
D4 RA5 RA2
D5 RA2 RA5
D6 RA2 RA1
D7 RA1 RA2
Using only "for" statements.
The original name was going to be "cFor", but that seemed
too potentially explosive.
*/
#asm
List p=16f84a
__config h'3ff1'
Radix hex
#endasm
int i, j, k, n;
main()
{
PORTA = 0;
CMCON0 = 7; // Turn off Comparators
ANSEL = 0; // Turn off ADC
k = 0; // Start at LED 0
for(;;) // Loop Forever
{
for (i = 0; i < 255; i++) // Simple Delay Loop
for (j = 0; j < 129; j++);
for (n = 0; (0 == k) && (0 == n); n++)
{ // Simulate "if (0 == k)"
PORTA = 0b010000;
TRISA = 0b001111;
} // rof
for (n = 0; (1 == k) && (0 == n); n++)
{ // Simulate "if (1 == k)"
PORTA = 0b100000;
TRISA = 0b001111;
} // rof
for (n = 0; (2 == k) && (0 == n); n++)
{ // Simulate "if (2 == k)"
PORTA = 0b010000;
TRISA = 0b101011;
} // rof
for (n = 0; (3 == k) && (0 == n); n++)
{ // Simulate "if (3 == k)"
PORTA = 0b000100;
TRISA = 0b101011;
} // rof
for (n = 0; (4 == k) && (0 == n); n++)
{ // Simulate "if (4 == k)"
PORTA = 0b100000;
TRISA = 0b011011;
} // rof
for (n = 0; (5 == k) && (0 == n); n++)
{ // Simulate "if (5 == k)"
PORTA = 0b000100;
TRISA = 0b011011;
} // rof
for (n = 0; (6 == k) && (0 == n); n++)
{ // Simulate "if (6 == k)"
PORTA = 0b000100;
TRISA = 0b111001;
} // rof
for (n = 0; (7 == k) && (0 == n); n++)
{ // Simulate "if (7 == k)"
PORTA = 0b000010;
TRISA = 0b111001;
} // rof
k = (k + 1) % 8; // Increment k within range of 0-7
} //
} //
___________________________________________________________________________
Commands for calculation
The example below shows sample commands for calculation.
#asm
List p=16f84a
__config h'3ff1'
Radix hex
#endasm
CBLOCK 0x20 ; Variable Declaration
i, j
ENDC
PAGE
org 0
nop ; Required for MPLAB ICD2
movlw 0x0F ; Initialize Variables
movwf i
movlw 0xF0
movwf j
clrw ; Clear WREG
; Z = 1
addwf i, w ; WREG = WREG + i
; = 0 + 0x0F
; = 0x0F
; Z = 0, C = 0, DC = 0
addwf i, w ; WREG = WREG + i
; = 0x0F + 0x0F
; = 0x1E
; Z = 0, C = 0, DC = 1
addwf i, w ; WREG = WREG + i
; = 0x1E + 0x0F
; = 0x2D
; Z = 0, C = 0, DC = 1
addwf j, w ; WREG = WREG + k
; = 0x2D + 0xF0
; = 0x(1)1D
; = 0x1D
; Z = 0, C = 1, DC = 0
addlw 0xE3 ; WREG = WREG + 0xE3
; = 0x1D + 0xE3
; = 0x(1)00
; = 0x00
; Z = 1, C = 1, DC = 1
goto $ ;
end
Code samples similar to Evil Genius with modifications by Engineering and Computer Works.
The above notes are samples of the engineering notes for the Microchip Embedded Systems notes. There would be more examples available from Engineering and Computer Works.
This method of programming involves Assembly language and C language which are compiled together.
Copyright 2012 ENGINEERING AND COMPUTER WORKS. All rights reserved.
ENGINEERING AND COMPUTER WORKS
Block 738, #12-373, Woodlands Circle, Singapore 730738;
Level 28, PJ Exchange, No. 16A, Persiaran Barat, 46050 Petaling Jaya, Selangor Darul Ehsan, Kuala Lumpur, Malaysia
ph: +65 9173 7839(Singapore) ; +6017 396 7471(Malaysia)
fax: +65 63680320 (Singapore) ;
alt: +1 (503) 928 7953 ;
chanjunt