Stdlib for Atmel AVR AT90S series.
This is a project with the purpose of providing fast and easy use of the microcontrollers when writting small/medium size programs.
This 'library' consists of two files. The "AVR_stdlib.inc" and the "AVR_stdlib.asm". The first file has all the required definitions and macros, while the second file has all the codes for the functions. The inc file must be included into the source before any macros of the library are used, and the asm file after (normally at the end of the source). For each macro used the preprocessor of assembler is instructed to include in the source the required asm code for them. Thus the program memory space required is limited to the minimum.
20000905:
New revision with some code optimizations for speed, fug fixes, and new functions for the EEPROM to write data in it, and for the SRAM to use the data segment for constants and variables. Also support for AT90S1200 was removed as its limited stack would create a lot of problems when using the library. Use AT90S2313 or SMDs if space matters.
20000901:
New revision with a few bug fixes and also new UART functions added. Now you can read and write from/to the UART bytes in hex form. Each byte is converted to and from ASCII. Also sone new macros to configure interrupt triggering are available.
20000822:
The current revision (20000822) includes macros for using the UART, the EEPROM, and configuring the controller. The most important feature is the variable declaration. This way the programmer doesn't have to care what registers are used by each sub-function or macro to keep them from mixing up. When a variable is declared the assembler searches the available registers for an unused one and then assigns the name to it. At the end for the variable's scope another macro must be used to unassign the register so the it can be used later. There is a limit of variables declared depending upon the available registers and if X,Y,Z are used (if __USE_XYZ__ is defined while compiling then the registers R26 to R31 are used for variables and not as the X,Y,Z pairs). Also wrappers for mnemonics like 'cpi','ldi' etc are included to transparently distinguish when an immediate or not, capable register is used and then use the proper mnemonics.
Not all of the functions and macros have been verified for proper operation. If anyone find any errors in the code then email me with the problem, quoting the revision of the library and the version of avra used. Include output dumps of the errors if possible.
If anyone wants to contribute in the development of this library by writing more functions/macros then just send send them to me and I will add them to the next revision.
Anyone is free to use this 'library' in his coding and all I want is just an acknowledgement.
AVR_stdlib.inc
AVR_stdlib.asm
moufa.asm (an example program that prints something to the serial port with only 3(!) lines of code)
Requires: avra assembler by John Anders Haugum.
Total functions available: 48
*NOTE* Use int and related macros only inside other macros and only at the beginning of the program to define custom variables. The scope of each variable is limited to the 'line of sight' between the declarations and undeclarations. Temporary variables not recommended for use by the called functions inside their scope.
*NOTE* The printEE/FL functions use the Z pair. So either make the caller function to use the X/Y pairs if needed or push and pop the Z pair before and after the library call.
20000905
- Constants:
- CB : carriage back
- Functions
- Time specific:
- delay10us : delay for 10us
- EEPROM
- putEEc var1(EE addr high),var2(EE addr low),var3 : write character $var3
- to EEPROM at address ($var1)($var2)
- putEEci EEaddress,var : write character $var to EEPROM at address $EEaddress
- SRAM
- [get,put]SRvar[X,Y,Z] SRaddress,var : write byte from $var to Data Segment
- (SRAM) address $SRaddress
20000901
- Constants:
- CR : carriage return
- LF : line feed
- NULL : zero
- Functions
- UART
- printHex var : print the hex represention of $var
- printHexi x : print the hex representation of byte x
- getHex var : get a byte from the UART in hex form and store it to $var
- Interrupts
- setint[0,1][ll,fe,re] : set INT0/1 low level/falling edge/rising edge triggered
20000822
- Compile-time definitions
- __CPU__ : define the CPU type used
- __CPU_KHZ__ : define the CPU core frequency
- __USE_XYZ__ : free XYZ double registers for use
- __UART_UBRR__ : set the UART baud rate (value depending upon core frequency)
- Macros
- Variable specific
- int var : declare a byte variable
- i_int var : declare a byte variable (use immediate register)
- word var1,var2 : declare a word from two bytes
- i_word var1,var2 : declare a word from two bytes (use immediate registers)
- free var : undeclare a byte variable
- freew var1,var2 : undeclare a worf of two bytes
- Command wrappers
- g[sbci,subi,cpi,andi,ori,ldi,sbr,cbr] : mnemonic wrappers to automatically
- distinguish if the operand registers are immediate or not, and
- act accordingly
- Functions
- System
- sp_init : initialize stack pointer
- suspend : suspend the controller
- powerdown : powerdown the controller
- ensleep : enable SLEEP mode
- dissleep : disable SLEEP mode
- UART
- uart_init : initialize UART with __UART_UBRR__
- [en,dis]u[r,t]x : enable/disable RX/TX IRQ
- [en,dis][rx,tx,udr]irq : enable/disable RX/TX/UDR IRQ
- [get,put]c var : read/write character from/to the UART to/from $var
- putci x : write character x to the UART
- printEEstr EEaddress : print a NULL terminated string from the
- EEPROM starting at address $EEaddress
- printFLstr FLASHaddress : print a NULL terminated string from the
- FLASH memory starting at address $FLASHaddress
- Time specific
- mdelay x : delay for x ms
- delay1ms : delay for 1 ms
- Interrupts
- [en,dis]int[0,1] : enable/disable INT0/INT1 IRQ
- EEPROM
- getEEc var1(EE addr high),var2(EE addr low),var3 : read a character
- from the EEPROM at address ($var1)($var2) and store it to $var3
- getEEci EEaddress,var : read a character from the EEPROM at address
- $EEaddress and store it to $var
- FLASH
- getFLc var1(FLASH addr high),var2(FLASH addr low),var3 : read a
- character from the FLASH memory at address ($var1)($var2) and
- store it to $var3
- getFLci FLASHaddress,var : read a character from the FLASH memory at
- address $FLASHaddress and store it to $var
|