PICSim  0.8.1
PICsim - PIC Simulator
picsim.h File Reference

PICsim - PIC Simulator - API. More...

#include "p16fxxx_defs.h"
#include "p16fxxxe_defs.h"
#include "p18fxxx_defs.h"
Include dependency graph for picsim.h:

Go to the source code of this file.

Data Structures

struct  picpin
 PICsim pin structure. More...
 
struct  _serial
 PICsim serial structure. More...
 
struct  _pic
 PICsim PIC structure. More...
 
struct  pic_desc
 

Macros

#define PICSIM
 
#define SERIAL_MAX   2
 
#define BUFFMAX   8192
 
#define PD_OUT   0x00
 
#define PD_IN   0x01
 
#define PT_CMOS   0x01
 
#define PT_TTL   0x02
 
#define PT_ANALOG   0x04
 
#define PT_ANAREF   0x05
 
#define PT_USART   0x06
 
#define PT_NC   0xFF
 
#define P16   1
 
#define P18   2
 
#define P16E   3
 
#define P16F84A   0x0560
 
#define P16F777   0x0DE0
 
#define P16F18855   0X306C
 
#define P18F452   0x0420
 
#define CFG_MCLR   0x01
 
#define CFG_WDT   0x02
 
#define CFG_DEBUG   0x04
 
#define CFG_WDT_DIV   0x08
 
#define PDIP   0
 
#define QFN   1
 
#define HEX_OK   0
 No erro

 
#define HEX_NFOUND   1
 File not found.
 
#define HEX_CHKSUM   2
 Checksum error.
 
#define HEX_NWRITE   3
 File write error.
 
#define P_VDD   &NO_IO[0]
 
#define P_VSS   &NO_IO[1]
 
#define P_RST   &NO_IO[2]
 
#define P_OSC   &NO_IO[3]
 
#define P_USB   &NO_IO[4]
 
#define P_NC   &NO_IO[5]
 
#define sfr_addr(fsr)   (fsr - pic->ram)
 Return the mapped address of FSR struct member
More...
 
#define PMAX   20
 
#define init_pic(function, family, ID)
 

Functions

int pic_set_serial (_pic *pic_, int nser, const char *name, int flowcontrol, int ctspin, int rtspin)
 Configure the serial port connection. More...
 
int pic_init (_pic *pic_, int processor, const char *fname, int leeprom, float freq)
 Initialize one pic object. More...
 
int pic_reset (int flags)
 Reset the microcontroller. More...
 
void pic_erase_flash (void)
 erase the microcontroller FLASH
 
void pic_step (void)
 Execute one simulation step. More...
 
void pic_end (void)
 finalize and free pic object internal memory
 
unsigned char pic_get_pin (unsigned char pin)
 Get digital value of one pin. More...
 
int pic_set_pin (unsigned char pin, unsigned char value)
 Set digital value of one pin. More...
 
int pic_set_apin (unsigned char pin, float value)
 Set digital value of one pin. More...
 
unsigned char pic_get_pin_type (unsigned char pin)
 Get type of one pin. More...
 
unsigned char pic_get_pin_dir (unsigned char pin)
 Get dir of one pin. More...
 
unsigned char pic_get_pin_DOV (unsigned char pin)
 Get Default Open Value of one pin (external PULL UP) More...
 
int pic_set_pin_DOV (unsigned char pin, unsigned char value)
 Set Default Open Value of one pin (external PULL UP) More...
 
void pic_icsp_init (void)
 Initialize P16 ICSP support.
 
int pic_icsp (void)
 Run P16 ICSP (must be pooling) More...
 
void pic_icsp_init18 (void)
 Initialize P18 ICSP support.
 
int pic_icsp18 (void)
 Run P18 ICSP (must be pooling) More...
 
int read_ihx (const char *fname, int leeprom)
 Read HEX file to P16 microcontroller. More...
 
int read_ihx_16e (const char *fname, int leeprom)
 Read HEX file to P16E microcontroller. More...
 
int read_ihx_18 (const char *fname, int leeprom)
 Read HEX file to P18 microcontroller. More...
 
int write_ihx (const char *fname)
 Dump all non volatile P16 microcontroller memory to HEX file. More...
 
int write_ihx16e (const char *fname)
 Dump all non volatile P16E microcontroller memory to HEX file. More...
 
int write_ihx18 (const char *fname)
 Dump all non volatile P18 microcontroller memory to HEX file. More...
 
int getproclist (char list[][30], int size)
 Return list name of supported processors
More...
 
unsigned int getprocbyname (const char *str)
 Return processor ID by name. More...
 
unsigned int getfprocbyname (const char *str)
 Return processor family ID by name. More...
 
unsigned int getfprocbynumber (int proc)
 Return processor family ID by ID. More...
 
char * getnamebyproc (int proc, char *str)
 Return processor name by ID. More...
 
const char * getFSRname_16 (unsigned int addr)
 Return P16 FSR name by address. More...
 
const char * getFSRname_16E (unsigned int addr)
 Return P16E FSR name by address. More...
 
const char * getFSRname_16E2 (unsigned int addr)
 Return P16E2 FSR name by address. More...
 
const char * getFSRname_18 (unsigned int addr)
 Return P18 FSR name by address. More...
 
const char * getPinName (_pic *pic, int pin, char *pname)
 Return pin name. More...
 
void pic_register (pic_desc picd)
 

Variables

unsigned char NO_IO [6]
 
_picpic
 global pointer
 
pic_desc PICS [PMAX]
 
int PIC_count
 

Detailed Description

PICsim - PIC Simulator - API.

Author
Luis Claudio Gamboa Lopes

PICsim emulates a microcontroller PIC16F84A/16F628/16F777/16F877A/18F452/18F4520/18F4550/18F4620 and periferics such as USART and timers, the simulator architecture permit easy implementation of external elements in c language.

See also
https://github.com/lcgamboa/picsim

Macro Definition Documentation

◆ init_pic

#define init_pic (   function,
  family,
  ID 
)
Value:
static pic_desc desc_ ## function = { ID , #function , family , function ## _start };\
static void __attribute__((constructor)) init_ ## function(void);\
static void init_ ## function (void){ \
pic_register(desc_ ## function);}

◆ sfr_addr

#define sfr_addr (   fsr)    (fsr - pic->ram)

Return the mapped address of FSR struct member

Parameters
fsrP16map_t, P16Emap_t or P18map_t struct member.
Returns
address of ram

Function Documentation

◆ getfprocbyname()

unsigned int getfprocbyname ( const char *  str)

Return processor family ID by name.

Parameters
strname of microcontoller
Returns
family ID of microcontroller

◆ getfprocbynumber()

unsigned int getfprocbynumber ( int  proc)

Return processor family ID by ID.

Parameters
procID of microcontoller
Returns
family ID of microcontroller

◆ getFSRname_16()

const char* getFSRname_16 ( unsigned int  addr)

Return P16 FSR name by address.

Parameters
addraddress of FSR
Returns
FSR name

◆ getFSRname_16E()

const char* getFSRname_16E ( unsigned int  addr)

Return P16E FSR name by address.

Parameters
addraddress of FSR
Returns
FSR name

◆ getFSRname_16E2()

const char* getFSRname_16E2 ( unsigned int  addr)

Return P16E2 FSR name by address.

Parameters
addraddress of FSR
Returns
FSR name

◆ getFSRname_18()

const char* getFSRname_18 ( unsigned int  addr)

Return P18 FSR name by address.

Parameters
addraddress of FSR
Returns
FSR name

◆ getnamebyproc()

char* getnamebyproc ( int  proc,
char *  str 
)

Return processor name by ID.

Parameters
procID of microcontoller
strstring to return the name of microcontroller
Returns
filled str parameter

◆ getPinName()

const char* getPinName ( _pic pic,
int  pin,
char *  pname 
)

Return pin name.

Parameters
pic_pointer to pic object
pinpin number
strstring to return the name of pin
Returns
filled str parameter

◆ getprocbyname()

unsigned int getprocbyname ( const char *  str)

Return processor ID by name.

Parameters
strname of microcontoller
Returns
ID of microcontroller

◆ getproclist()

int getproclist ( char  list[][30],
int  size 
)

Return list name of supported processors

Parameters
variableto return the number of supported processors
Returns
array of names

◆ pic_get_pin()

unsigned char pic_get_pin ( unsigned char  pin)

Get digital value of one pin.

Parameters
pinpin number
Returns
pin value 0 or 1

◆ pic_get_pin_dir()

unsigned char pic_get_pin_dir ( unsigned char  pin)

Get dir of one pin.

Parameters
pinpin number
Returns
pin dir

◆ pic_get_pin_DOV()

unsigned char pic_get_pin_DOV ( unsigned char  pin)

Get Default Open Value of one pin (external PULL UP)

Parameters
pinpin number
Returns
value 0 or 1

◆ pic_get_pin_type()

unsigned char pic_get_pin_type ( unsigned char  pin)

Get type of one pin.

Parameters
pinpin number
Returns
pin types

◆ pic_icsp()

int pic_icsp ( void  )

Run P16 ICSP (must be pooling)

Returns
Return 1 if success, 0 otherwise

◆ pic_icsp18()

int pic_icsp18 ( void  )

Run P18 ICSP (must be pooling)

Returns
Return 1 if success, 0 otherwise

◆ pic_init()

int pic_init ( _pic pic_,
int  processor,
const char *  fname,
int  leeprom,
float  freq 
)

Initialize one pic object.

Use to initialize the _pic object structure

Parameters
pic_pointer to pic object
processormicrocontroller ID
fnameName of hex file to load
leepromLoad EEprom from file if equal to 1
freqFrequency of microcontoller
Returns
Return 1 if success, 0 otherwise

◆ pic_reset()

int pic_reset ( int  flags)

Reset the microcontroller.

Reset the microcontroller to initial state

Parameters
flags0 = WDT reset 1 = Power on reset -1 = MCLRE pin reset
Returns
Return 1 if success, 0 otherwise

◆ pic_set_apin()

int pic_set_apin ( unsigned char  pin,
float  value 
)

Set digital value of one pin.

Parameters
pinpin number
valuepin analog value from 0 to 5
Returns
Return 1 if success, 0 otherwise

◆ pic_set_pin()

int pic_set_pin ( unsigned char  pin,
unsigned char  value 
)

Set digital value of one pin.

Parameters
pinpin number
valuepin value 0 or 1
Returns
Return 1 if success, 0 otherwise

◆ pic_set_pin_DOV()

int pic_set_pin_DOV ( unsigned char  pin,
unsigned char  value 
)

Set Default Open Value of one pin (external PULL UP)

Parameters
pinpin number
valuepin default value 0 or 1
Returns
Return 1 if success, 0 otherwise

◆ pic_set_serial()

int pic_set_serial ( _pic pic_,
int  nser,
const char *  name,
int  flowcontrol,
int  ctspin,
int  rtspin 
)

Configure the serial port connection.

Use to link the PICSim serial to one serial port

Parameters
pic_pointer to pic object
nsernumber of serial
nameName of serial port
flowcontroluse flowcontrol
ctspinCTS pin if flowcontrol = 1
rtspinRTS pin if flowcontrol = 1
Returns
Return 0 if success, 1 otherwise

◆ pic_step()

void pic_step ( void  )

Execute one simulation step.

Execute one simulation step, must be call continuously to run the program in pic flash memory

◆ read_ihx()

int read_ihx ( const char *  fname,
int  leeprom 
)

Read HEX file to P16 microcontroller.

Parameters
fnamename of .hex file
leepromflag to load or not the microcontroller data eeprom form file
Returns
HEX functions errors

◆ read_ihx_16e()

int read_ihx_16e ( const char *  fname,
int  leeprom 
)

Read HEX file to P16E microcontroller.

Parameters
fnamename of .hex file
leepromflag to load or not the microcontroller data eeprom form file
Returns
HEX functions errors

◆ read_ihx_18()

int read_ihx_18 ( const char *  fname,
int  leeprom 
)

Read HEX file to P18 microcontroller.

Parameters
fnamename of .hex file
leepromflag to load or not the microcontroller data eeprom form file
Returns
HEX functions errors

◆ write_ihx()

int write_ihx ( const char *  fname)

Dump all non volatile P16 microcontroller memory to HEX file.

Parameters
fnamename of .hex file
Returns
HEX functions errors

◆ write_ihx16e()

int write_ihx16e ( const char *  fname)

Dump all non volatile P16E microcontroller memory to HEX file.

Parameters
fnamename of .hex file
Returns
HEX functions errors

◆ write_ihx18()

int write_ihx18 ( const char *  fname)

Dump all non volatile P18 microcontroller memory to HEX file.

Parameters
fnamename of .hex file
Returns
HEX functions errors
pic_desc
Definition: picsim.h:651