CC5X PRICES BUY NOW DOWNLOAD Introduction Features - Math library - Installation - Devices Examples FAQ NEWS Planned Feedback Support Distributors CC8E Leanslice HOME |
Example CodeThe example code are supplied in TXT files including the generated ASM files. int16xx.txt (asm) : simple interrupt example Small C exampleThe remaining of this page contains a small C program example and some of the files generated by CC5X.
|
/* global variables */ char a; bit b1, b2; /* assign names to port pins */ #pragma bit in @ PORTB.0 #pragma bit out @ PORTB.1 void sub( void) { char i; /* a local variable */ /* generate 20 pulses */ for ( i = 0; i < 20; i++) { out = 1; nop(); out = 0; } } void main( void) { // if (TO == 1 && PD == 1 /* power up */) { // WARM_RESET: // clearRAM(); // clear all RAM if required // } /* first decide the initial output level on the output port pins, and then define the input/output configuration. This avoids spikes at the output pins. */ PORTA = 0b.0010; /* out = 1 */ TRISA = 0b.1111.0001; /* xxxx 0001 */ a = 9; /* value assigned to global variable */ do { if (in == 0) /* stop if 'in' is low */ break; sub(); } while ( -- a > 0); /* 9 iterations */ // if (some condition) // goto WARM_RESET; /* main is terminated by a SLEEP instruction */ }
CC5X Version 3.4, Copyright (c) B Knudsen Data, Norway 1992-2009 --> EXTENDED edition, 8-32 bit int, 16-32 bit float, 32k code test\sample1.c: 24. Jun 2009 11:04 Chip = 16C54 RAM: 00h : -------= .6****** ******** ******** RAM usage: 3 bytes (1 local), 22 bytes free File 'sample1.fcs' Optimizing - removed 3 instructions (-11 %) File 'sample1.var' File 'sample1.asm' File 'sample1.lst' File 'sample1.cod' File 'sample1.occ' File 'sample1.hex' Total of 24 code words (4 %)
; CC5X Version 3.4, Copyright (c) B Knudsen Data ; C compiler for the PICmicro family ; ************ 24. Jun 2009 11:04 ************* processor 16C54 radix DEC PORTB EQU 0x06 Carry EQU 0 a EQU 0x08 in EQU 0 out EQU 1 i EQU 0x07 ; FILE test\sample1.c ; ;/* global variables */ ;char a; ;bit b1, b2; ; ;/* assign names to port pins */ ;bit in @ PORTB.0; ;bit out @ PORTB.1; ; ;void sub( void) ;{ sub ; char i; /* a local variable */ ; ; /* generate 20 pulses */ ; for ( i = 0; i < 20; i++) { CLRF i m001 MOVLW 20 SUBWF i,W BTFSC 0x03,Carry GOTO m002 ; out = 1; BSF 0x06,out ; nop(); NOP ; out = 0; BCF 0x06,out ; } INCF i,1 GOTO m001 ;} m002 RETLW 0 ; ; ; ;void main( void) ;{ main ; // if (TO == 1 && PD == 1 /* power up */) { ; // WARM_RESET: ; // clearRAM(); // clear all RAM ; // } ; ; /* NOTE 1: some devices have a comparator module ; that have to be switched off to use certain ; pins as digital IO */ ; //CMCON = 0x07; // switch comparators off ; ; /* NOTE 2: devices having AD converter may need to ; configure the pins assigned to 'in' and 'out' as ; digital IO */ ; //ADCON1 = .. ; ; /* First decide the initial output level on the ; output port pins, and then define the input/ ; output configuration. This avoids spikes at the ; output pins. */ ; ; PORTB = 0b.0000.0010; /* out = 1 */ MOVLW 2 MOVWF PORTB ; TRISB = 0b.1111.0001; /* xxxx 0001 */ MOVLW 241 TRIS PORTB ; ; a = 9; /* value assigned to global variable */ MOVLW 9 MOVWF a ; ; do { ; if (in == 0) /* stop if 'in' is low */ m003 BTFSS 0x06,in ; break; GOTO m004 ; sub(); CALL sub ; } while ( -- a > 0); /* 9 iterations */ DECFSZ a,1 GOTO m003 ; ; // if (some condition) ; // goto WARM_RESET; ; ; /* main is terminated by a SLEEP instruction */ ;} m004 SLEEP ORG 0x01FF GOTO main END ; *** KEY INFO *** ; 0x0000 11 word(s) 2 % : sub ; 0x000B 12 word(s) 2 % : main ; RAM usage: 3 bytes (1 local), 22 bytes free ; Maximum call level: 1 ; Total of 24 code words (4 %)
CC5X Version 3.4, Copyright (c) B Knudsen Data. * FUNCTION CALL STRUCTURE F: sub :#1 F: main :#0 sub : #1 L0 main L1 sub
CC5X Version 3.4, Copyright (c) B Knudsen Data * VARIABLE LIST FILE Source 'test\sample1.c' Chip = 16C54 Sorted by address. X := P:direct assigned, L:local, G:global, E:extern, R:overlapping, C:const B := bank Size := number of bytes #AC := number of direct accesses X B Address Size #AC Name P - 0x000 1 : 0: INDF P - 0x001 1 : 0: TMR0 P - 0x002 1 : 0: PCL P - 0x003 1 : 0: STATUS P - 0x003.0 0 : 1: Carry P - 0x003.1 0 : 0: DC P - 0x003.2 0 : 0: Zero_ P - 0x003.3 0 : 0: PD P - 0x003.4 0 : 0: TO P - 0x003.5 0 : 0: PA0 P - 0x003.6 0 : 0: PA1 P - 0x003.7 0 : 0: PA2 P - 0x004 1 : 0: FSR P - 0x004.5 0 : 0: FSR_5 P - 0x004.6 0 : 0: FSR_6 P - 0x005 1 : 0: PORTA P - 0x006 1 : 2: PORTB P - 0x006.0 0 : 1: in P - 0x006.1 0 : 2: out L - 0x007 1 : 3: i G - 0x008 1 : 2: a G - 0x009.0 0 : 0: b1 G - 0x009.1 0 : 0: b2