
| CC5X PRICES BUY NOW DOWNLOAD Introduction Features - math library - installation and MPLAB support - supported chips Examples FAQ NEWS Planned Feedback Support Links 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.1A, Copyright (c) B Knudsen Data, Norway 1992-2000 --> STANDARD edition, 8-24 bit int, 24-32 bit float, 8k code test\sample1.c: 28. Oct 2000 10:50 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.hex' Total of 24 instructions (4 %)
; CC5X Version 3.1A, Copyright (c) B Knudsen Data
; C compiler for the PICmicro family
; ************ 28. Oct 2000 10:50 *************
processor 16C54
radix DEC
PORTA EQU 0x05
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 */
;#pragma bit in @ PORTB.0
;#pragma 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 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 */
MOVLW .2
MOVWF PORTA
; TRISA = 0b.1111.0001; /* xxxx 0001 */
MOVLW .241
TRIS PORTA
;
; 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
CC5X Version 3.1A, Copyright (c) B Knudsen Data.
* FUNCTION CALL STRUCTURE
F: sub :#1
F: main :#0
sub : #1
L0 main
L1 sub
CC5X Version 3.1A, Copyright (c) B Knudsen Data. * VARIABLE LIST FILE Source 'test\sample1.c' Chip = 16C54 === Sorted by address === [-] 0x000 : 0: INDF [-] 0x001 : 0: TMR0 [-] 0x002 : 0: PCL [-] 0x003 : 0: STATUS [-] 0x003.0 : 1: Carry [-] 0x003.1 : 0: DC [-] 0x003.2 : 0: Zero_ [-] 0x003.3 : 0: PD [-] 0x003.4 : 0: TO [-] 0x003.5 : 0: PA0 [-] 0x003.6 : 0: PA1 [-] 0x003.7 : 0: PA2 [-] 0x004 : 0: FSR [-] 0x004.5 : 0: FSR_5 [-] 0x004.6 : 0: FSR_6 [-] 0x005 : 2: PORTA [-] 0x006 : 0: PORTB R [-] 0x006.0 : 1: in R [-] 0x006.1 : 2: out L [-] 0x007 : 3: i G [-] 0x008 : 2: a G [-] 0x009.0 : 0: b1 G [-] 0x009.1 : 0: b2