// File vp_test.c --test program for CC1B compiler #pragma chip SX48 // select device //--------------------------------------------------------------------------------- #if defined _CHIP_SX18_ || defined _CHIP_SX20_ || defined _CHIP_SX28_ #pragma asmDir: DEVICE OSCHS1, TURBO, STACKX, OPTIONX ;SX18/20/28 #endif #if defined _CHIP_SX48_ || defined _CHIP_SX52_ #pragma asmDir: DEVICE OSCHS1 ;SX48/52 #endif #pragma asmDir: IRC_CAL IRC_SLOW #pragma asmDir: FREQ 20_000_000 #pragma asmDir: RESET main #pragma asmDir: ID 'project' //====================================================== #define CPUFREQ 20000000 #define MAXBAUD 57600 //#define ISRTHREADS 4 #include //#pragma mainStack 0 @0xF0 //allocate locals from ram address 0xF0 upwards (use only when <= 16 locals) // ************************************************ // ************************************************ // MACRO DEFINITIONS AND CONSTANTS // Area for storage of constant data (at end of program code) // The size of the area is set by the constant after _CHIP_CODESIZE_ // The minimal constant value is 1. Set it to the minimal value as required by the application. #pragma cdata[_CHIP_CODESIZE_ - 0x100] // ************************************************ // ************************************************ // IO PORT DEFINITIONS bit pinTX @RA.1; bit pinRX @RA.2; /* * CONNECTION diagram * * | +5V * / * RA.1 -----[4k7]-----| PNP * \ * +----- SOUT -------------> To PC comport receive * [4k7] * | * RA.2 -----[33k]------+----- SIN ---------------< From PC comport transmit */ // ************************************************ // ************************************************ // GLOBAL VARIABLE DEFINITIONS #pragma membank0 //allocate globals from global ram //define variables that must reside in global ram here #pragma membank1 //allocate globals from ram address 0x10 upwards // ************************************************ // ************************************************ // PROTOTYPES AND CODEPAGES /* Prototypes are needed when a function is called before it is defined. It can also be used for fine tuning the code layout (i.e. which codepage to use for a function). */ // ************************************************ // ************************************************ // INCLUDED C FILES AND MATH ROUTINES #pragma codepage 1 #include #include #pragma membank6 #pragma codepage 2 #include #pragma membank9 #pragma codepage 3 #include #pragma membank11 // ************************************************ // ************************************************ // VIRTUAL PERIPHERAL AND OBJECT DECLARATIONS #pragma cdata.VPDEFINITIONS //required label to identify start of VP definitions vpUartTx(TX1,PORTPIN_RA1,HIGHOUTPUT_HIGHOUTPUT,0,0,9600,1,E72) vpUartRx(RX1,PORTPIN_RA2+PORTPIN_INV,LOWINPUT_LOWINPUT,0,0,9600,1,E72) #define VPSLOTS 2 //set number of VP slots (SX18/20/28: 1 to 6, SX48/52: 1 to 8) #define VPRAM 0x30 //set first vp ram bank (total banks allocated is VPSLOTS+1) #include #pragma codepage 4 #define TASKS 2 //number of tasks that can run concurrently #define TASKTICK 60 //number of ISR ticks that make up a tasktick #define TASKLIST 0x70 //locates TaskList at 0x70 #include // ************************************************ // ************************************************ // INTERRUPT SUPPORT //include global variables for interrupt here #pragma unlockISR #pragma origin 0 // without #pragma unlockISR, interrupt must be located first on codepage 0 #pragma asmDir: JMP @iServer #pragma asmDir: JMP @TaskSchedule #pragma origin 4 interrupt iServer(void) { /* NOTE: W, STATUS and FSR are automatically saved to and restored from shadow registers */ #if defined _CHIP_SX18_ || defined _CHIP_SX20_ || defined _CHIP_SX28_ _IsrMode = MODE; //save M #endif char i,vp; _IsrBank = VPRAM; for (i=0; i