In the stdio.h the type FILE is defined as:
extern FILE * stdout;
pointer type | <7:6> | <5> | <4> | <3:0> | rest of the pointer | descrption |
stream | 00 | 1 | 0 | nnnn | uuuuuuuu uuuuuuuu | upper byte high nubble is 0x2n, the rest are zeroes |
Currently implemented there are 3 types of streams defined:
stream type | value | module | description |
STREAM_USART | 0x200000UL | USART | Writes/Reads characters via the USART peripheral |
STREAM_MSSP | 0x210000UL | MSSP | Writes/Reads characters via the MSSP peripheral |
STREAM_USER | 0x2f0000UL | (none) | Writes/Reads characters via used defined functions |
The stream identifiers are declared as macros in the stdio.h header.
In the libc library there exist the functions that are used to write to each of the above streams. These are
{
PORTA = c; /* dump character c to PORTA */
}
void main(void)
{
stdout = STREAM_USER; /* this is not necessary, since stdout points
* by default to STREAM_USER */
printf (''This is a printf test\n'');
}
PIC16 contains an implementation of the printf-family of functions. There exist the following functions:
extern unsigned int vsprintf(char *buf, char *fmt, va_list ap);
extern unsigned int printf(char *fmt, ...);
extern unsigned int vprintf(char *fmt, va_lista ap);
extern unsigned int fprintf(FILE *fp, char *fmt, ...);
extern unsigned int vfprintf(FILE *fp, char *fmt, va_list ap);
The PIC18F family of microcontrollers supports a number of interrupt sources. A list of these interrupts is shown in the following table:
signal name | description | signal name | descritpion |
SIG_RB | PORTB change interrupt | SIG_EE | EEPROM/FLASH write complete interrupt |
SIG_INT0 | INT0 external interrupt | SIG_BCOL | Bus collision interrupt |
SIG_INT1 | INT1 external interrupt | SIG_LVD | Low voltage detect interrupt |
SIG_INT2 | INT2 external interrupt | SIG_PSP | Parallel slave port interrupt |
SIG_CCP1 | CCP1 module interrupt | SIG_AD | AD convertion complete interrupt |
SIG_CCP2 | CCP2 module interrupt | SIG_RC | USART receive interrupt |
SIG_TMR0 | TMR0 overflow interrupt | SIG_TX | USART transmit interrupt |
SIG_TMR1 | TMR1 overflow interrupt | SIG_MSSP | SSP receive/transmit interrupt |
SIG_TMR2 | TMR2 matches PR2 interrupt | ||
SIG_TMR3 | TMR3 overflow interrupt |
The prototypes for these names are defined in the header file signal.h .
In order to simplify signal handling, a number of macros is provided:
#include <signal.h>
DEF_INTHIGH(high_int)
DEF_HANDLER(SIG_TMR0, _tmr0_handler)
DEF_HANDLER(SIG_BCOL, _bcol_handler)
END_DEF
SIGHANDLER(_tmr0_handler)
{
/* action to be taken when timer 0 overflows */
}
SIGHANDLERNAKED(_bcol_handler)
{
_asm
/* action to be taken when bus collision occurs */
retfie
_endasm;
}