Introduction
This is the documentation of using the picsim simulation library functions.
Library functions usage simple example
Demonstration of a simple example of using picsim library functions
picsim_simple.c
#include<picsim/picsim.h>
#include<stdio.h>
int main()
{
int i;
unsigned char val;
for(i=0;i<1000;i++)
{
}
}
int pic_set_pin(_pic *pic_, unsigned char pin, unsigned char value)
Set digital value of one pin.
int pic_init(_pic *pic_, int processor, const char *fname, int leeprom, float freq)
Initialize one pic object.
void pic_end(_pic *pic_)
finalize and free pic object internal memory
unsigned char pic_get_pin(_pic *pic_, unsigned char pin)
Get digital value of one pin.
unsigned int getprocbyname(const char *str)
Return processor ID by name.
void pic_step(_pic *pic_)
Execute one simulation step.
int pic_set_serial(_pic *pic_, int nser, const char *name, int flowcontrol, int ctspin, int rtspin)
Configure the serial port connection.
unsigned char print
print information ON/OFF
Definition picsim.h:282
Makefile
CC= gcc
FLAGS= -Wall -ggdb
all: picsim_simple.c
$(CC) $(FLAGS) picsim_simple.c -o picsim_simple -lpicsim
clean:
rm -rf picsim_simple
Library functions usage realtime example
Demonstration of a realtime Linux example of using picsim library functions
realtime.c
#include <picsim/picsim.h>
#include <stdio.h>
#include <sys/time.h>
#include <signal.h>
#include <unistd.h>
#include <stdlib.h>
#define FREQ 4000000L
void timer_callback(int signum)
{
unsigned char PORTB;
static unsigned char PORTB_old;
const unsigned int nsteps = 100e-3 / (4.0 / pic1.
freq);
for (int i = 0; i < nsteps; i++)
{
PORTB = 0;
PORTB |= pic1.pins[6 - 1].
value;
PORTB |= pic1.pins[7 - 1].
value << 1;
PORTB |= pic1.pins[8 - 1].
value << 2;
PORTB |= pic1.pins[9 - 1].
value << 3;
PORTB |= pic1.pins[10 - 1].
value << 4;
PORTB |= pic1.pins[11 - 1].
value << 5;
PORTB |= pic1.pins[12 - 1].
value << 6;
PORTB |= pic1.pins[13 - 1].
value << 7;
if (PORTB != PORTB_old)
{
PORTB_old = PORTB;
printf("PORTB =0x%02X\n", PORTB);
}
}
}
void ctrlc_callback(int signum)
{
printf("end\n");
exit(0);
}
int main()
{
struct itimerval new_timer;
struct itimerval old_timer;
new_timer.it_value.tv_sec = 0;
new_timer.it_value.tv_usec = 100 * 1000;
new_timer.it_interval.tv_sec = 0;
new_timer.it_interval.tv_usec = 100 * 1000;
setitimer(ITIMER_REAL, &new_timer, &old_timer);
signal(SIGALRM, timer_callback);
signal(SIGINT, ctrlc_callback);
while (sleep(10))
;
}
float freq
frequency
Definition picsim.h:311
unsigned char value
value
Definition picsim.h:96
Makefile
CC= gcc
FLAGS= -ggdb -Wall
all: realtime
realtime: realtime.c
$(CC) $(FLAGS) realtime.c -o realtime -lpicsim
clean:
rm -rf realtime