90 likes | 230 Views
C Examples 2. Download Links. dsPIC30F4011/4012 Data Sheet dsPIC30F4013/3014 dsPIC30F Family Reference Manual MikroC MikroC Manual MikroC Quick Reference. Switch + LED (SWITCH12). void main () { ADPCFG = 0xFFFF; TRISF=0b000001; PORTF=0x00;
E N D
Download Links • dsPIC30F4011/4012 Data Sheet • dsPIC30F4013/3014 • dsPIC30F Family Reference Manual • MikroC • MikroC Manual • MikroC Quick Reference
Switch + LED(SWITCH12) • void main () • { • ADPCFG = 0xFFFF; • TRISF=0b000001; • PORTF=0x00; • while(1) • { • if((PORTF&0b000001)==1) // Switch at PORTF Bit 0 • {PORTF.F1=PORTF.F1^1;} // Toggles PORTF Bit 1 • } • }
Key DEBOUNCING – 1(SWITCH2) • void main () • { • int i; • const int Tenms = 16667; • ADPCFG = 0xFFFF; • TRISF=0b000001; • PORTF=0x00; • while(1) • { • i = 0; // Wait 10 ms for Button Up • while (i < Tenms) • { • if (1 == PORTF.F0) // Button Down/Start over • { • i = 0; • } • else // Button Up/Increment Count • { • i = i + 1; • } // • } // • i = 0; // Wait 10 ms for Button Down • while (i < Tenms) • { • if (0 == PORTF.F0 ) // Button Up/Start over • i = 0; • else // Button Down/Increment Count • i = i + 1; • } • PORTF.F1=PORTF.F1^1; // Toggle LED to Turn ON/OFF LED • } • } Adapted from 123 PIC Experiments for the EVIL GENIOUS by MYKE PREDKO
Key DEBOUNCING – 1(SWITCH2) • ;SWITCH2.c,24 :: while (i < Tenms) • $0144 $ L_main_6: • $0144 $470060 ADD W14, #0, W0 • $0146 $780110 MOV [W0], W2 • $0148 $4700E2 ADD W14, #2, W1 • $014A $510011 SUB W2, [W1], W0 • $014C $3D000D BRA GE L_main_7, L_main_7 • ;SWITCH2.c,25 :: if (0 == PORTF.F0) // Button Up/Start over • $014E $801700 MOV PORTF, W0 • $0150 $6000E1 AND W0, #1, W1 • $0152 $108060 SUBR W1, #0, W0 • $0154 $3A0004 BRA NZ L_main_8, L_main_8 • ;SWITCH2.c,26 :: i = 0; • $0156 $200000 MOV #0, W0 • $0158 $780F00 MOV W0, [W14] • $015A $040164 GOTO L_main_9 • $015E $ L_main_8: • ;SWITCH2.c,28 :: i = i + 1; • $015E $200011 MOV #1, W1 • $0160 $470060 ADD W14, #0, W0 • $0162 $408810 ADD W1, [W0], [W0] • $0164 $ L_main_9: • $0164 $040144 GOTO L_main_6 • $0168 $ L_main_7: • ;SWITCH2.c,30 :: PORTF.F1=PORTF.F1^1; // Toggle LED to Turn
SWITCH 12 • void main () • { • int start = 0; • ADPCFG = 0xFFFF; • TRISF=0b000001; • PORTF=0x00; • while(1) • { • if (Button(&PORTF, 0, 1, 1)) // Switch at PORTF Bit 0 • start = 1; • if (start&&Button(&PORTF, 0, 1, 0)) // Switch at PORTF Bit 0 • { • start=0; • PORTF.F1=PORTF.F1^1; // Toggles PORTF Bit 1 • } • } • }