PIC10 Basic Compiler Library Support


The library support is a new way for the basic statements implementation.
This is indeed an advanced feature, however that is a way that can be used by both the author and the users to extend the compiler language from the external library files.
The information is loaded from the external textual .lib files stored in the OshonSoft application data folder.
OshonSoft .lib files are documented enough with comments covering all the currently available features of the library support.
Library files can be edited by Notepad, or any other plain text editor.
 
 

oshonsoftpic10-adc.lib file:
 
//the concept is that one library group contains the implementation of one new language functionality - one or more related statements or functions
//library items contain different implementations of the same functionality for different groups of microcontrollers
//#lib_item_begin must be followed by #processor
//#statement_begin, #statement_type, #argument sequence must be fulfilled for proper library load
 
//#processor comma-separated list of processors, x can be used as a wild card character
//#processor can be used in multiple lines to quote all devices if needed
//#parameter is used to implement #define parameters needed for the statement implementation
//#parameter const, parameter_name, allowed_range, default_value
//#parameter symbol, parameter_name, type (pin, bit, byte, address of), system_bit or system_register
//'pin' type is used for the bits in the PORT registers
//'address of' type will implement a constant parameter
//#variable is used to declare global system variables
//#variable variable_name, type (byte, word)
//#statement_begin statement_name [argument1_name[, argument2_name[, ...]]]
//#statement_type type (procedure; inline; function, f_type (byte, word))
//#argument argument_name, type (byte, byte system xx, word, word system xx), passing_type
//the default type of the system variables can not be changed with #argument
//passing_type (byval, byval allowed_constant_range, byref, byrefout) for statement_type procedure and inline
//passing_type (byval, byval allowed_constant_range) for statement_type function
//allowed_constant_range can contain arithmetic expressions in brackets, like 0-[EEPROM_Num-1]
 
//used to define parameters and statements that are not available or not applicable for the current item devices
//#parameter n/a, parameter_name
//#statement n/a, statement_name
 
//used to define alternative names for the parameter and statement names defined in the library group
//#alias_for <library_defined_element_name>, <new_alternative_name>
//used to define code variations among processors when only one or more register names in the code should be replaced with their alternatives
//#alternate_reg_name <register_name_used_in_code>, <alternate_register_name>
 
//code section can contain both inline assembler and basic language lines of code
//symbol and const parameters can be used directly in the assembler lines of code
//calculate[] or calc[] macro is available
//calculate[] must be used to enter the parameter value in the basic code, will be replaced with the value of the parameter
//calculate[] can be used to perform one arithmetic operation, will be replaced with the value of the result
//calc[] arithmetic operators: +, -, *, /, % (modulus or remainder operator), \ (division returning integer result)
//calc[] macros can be nested
//reg_addr[] macro will be replaced with the register address; if not found, -1 is returned
//#if [], #endif macro is available
//#if comparison operators: ==,<>,<,>,<=,>=
//Clock_Freq in MHz is available as an argument
//Flash_Num and EEPROM_Num (total number of memory locations) are available as arguments
 
//be careful that basic statements like WaitUs also make use of the system registers and can alter those values
//when using inline assembler code, be careful that basic statements expect to be called with BANK zero selected
//#banksel register_name_or_address
//#banksel directive should be used before any register access with assembler code, in order to use the compiler internal memory banking optimizations
 
//special function registers are declared in basic code as byte variables; if needed, this byte variable type can be changed with #redim directive
//#redim register_name new_type (byte, word)
 
//#pagesel directive should be used before all the GOTO and CALL instructions in the code
//#pagesel will be used by the compiler to setup the appropriate page bits in the PCLATH register for the next GOTO or CALL instruction
 
//list of available compiler system byte registers (bank 0): R0L, R0H, R1L, R1H, R2L, R2H, R3L, R3H, R4L, R4H, R5L, R5H
//list of available compiler system word registers (bank 0): R0HL, R1HL, R2HL, R3HL, R4HL, R5HL
 
 
#lib_name OshonSoft ADC Module Library
 
 
#lib_group_begin //ADC_Read statement
//for backward compatibility
#alias_for ADC_Sample_uS, ADC_SAMPLEUS
#alias_for ADC_Clk, ADC_CLOCK
#alias_for ADC_Read, Adcin
 
#lib_item_begin
//ADCON0, bank0,
//ANS1 ANS0 ADCS1 ADCS0 CHS1 CHS0 GO/DONE ADON
//ADRES, bank0,
#processor 12f510, 16f506
#parameter const, ADC_Sample_uS, 0-255, 20
#parameter const, ADC_Clk, 0-3, 3
        #statement_begin ADC_Read adc_channel, adc_result
        #statement_type procedure
        #argument adc_channel, byte system R0L, byval 0-3
        #argument adc_result, byte system ADRES, byrefout
        #code_begin
        //
        rlf R0L,f
        rlf R0L,f
        movlw 0x0c
        andwf R0L,f
        movlw 0xc0
        andwf ADCON0,f
        movlw calc[calc[ADC_Clk * 16] + 1] //1-ADON
        iorwf R0L,w
        iorwf ADCON0,f
        //
        WaitUs calculate[ADC_Sample_uS]
        //
        bsf ADCON0,GO
        l1:
        #pagesel
        btfsc ADCON0,GO
        goto l1
        bcf ADCON0,ADON
        //
        #code_end
        #statement_end
#lib_item_end
 
#lib_item_begin
//ADCON0, bank0,
//ANS1 ANS0 CHS1 CHS0 GO/DONE ADON
//ADRES, bank0,
#processor 10f220, 10f222
#parameter const, ADC_Sample_uS, 0-255, 20
#parameter n/a, ADC_Clk
        #statement_begin ADC_Read adc_channel, adc_result
        #statement_type procedure
        #argument adc_channel, byte system R0L, byval 0-3
        #argument adc_result, byte system ADRES, byrefout
        #code_begin
        //
        rlf R0L,f
        rlf R0L,f
        movlw 0x0c
        andwf R0L,f
        movlw 0xc0
        andwf ADCON0,f
        incf R0L,w //1-ADON
        iorwf ADCON0,f
        //
        WaitUs calculate[ADC_Sample_uS]
        //
        bsf ADCON0,GO
        l1:
        #pagesel
        btfsc ADCON0,GO
        goto l1
        bcf ADCON0,ADON
        //
        #code_end
        #statement_end
#lib_item_end
 
#lib_item_begin
#processor 10f200, 10f202, 10f204, 10f206
#processor 12f508, 12f509, 16f505
#processor 16f54, 16f57, 16f59
#parameter n/a, ADC_Sample_uS
#parameter n/a, ADC_Clk
#statement n/a, ADC_Read
#lib_item_end
#lib_group_end
 
 
#lib_group_begin //All_Digital statement
//for backward compatibility
#alias_for All_Digital, AllDigital
 
#lib_item_begin
#processor 12f510, 16f506
#processor 10f220, 10f222
#processor 10f204, 10f206
        #statement_begin All_Digital
        #statement_type inline
        #code_begin
        //
        #if [reg_addr[ADCON0] >= 0] ADCON0.ANS0 = 0
        #if [reg_addr[ADCON0] >= 0] ADCON0.ANS1 = 0
        #if [reg_addr[CM1CON0] >= 0] CM1CON0.C1ON = 0
        #if [reg_addr[CM2CON0] >= 0] CM2CON0.C2ON = 0
        #if [reg_addr[VRCON] >= 0] VRCON.VROE = 0
        #if [reg_addr[CMCON0] >= 0] CMCON0.CMPON = 0
        //
        #code_end
        #statement_end
#lib_item_end
 
#lib_item_begin
#processor 10f200, 10f202
#processor 12f508, 12f509, 16f505
#processor 16f54, 16f57, 16f59
#statement n/a, All_Digital
#lib_item_end
#lib_group_end