Skip to content

Commit

Permalink
docs examples updated
Browse files Browse the repository at this point in the history
  • Loading branch information
lcgamboa committed Sep 14, 2024
1 parent a2a5075 commit 1ff7822
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Build picsim
on: [push]
jobs:
build-macos:
runs-on: macos-11
runs-on: macos-12
steps:
- uses: actions/checkout@v2
- name: Build
Expand Down
15 changes: 15 additions & 0 deletions docs/examples/realtime/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

CC= gcc

FLAGS= -ggdb -Wall

all: realtime

realtime: realtime.c
$(CC) $(FLAGS) realtime.c -o realtime -lpicsim

clean:
rm -rf realtime



72 changes: 72 additions & 0 deletions docs/examples/realtime/realtime.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@

#include <picsim/picsim.h>
#include <stdio.h>
#include <sys/time.h>
#include <signal.h>
#include <unistd.h>
#include <stdlib.h>


#define FREQ 4000000L

static _pic pic1;

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++)
{
pic_step(&pic1);

//READ pins
// PORTB |= pic_get_pin(&pic1, 6);
// use direct access instead pic_get_pin to speed up

PORTB = 0;
PORTB |= pic1.pins[6 - 1].value; // RB0
PORTB |= pic1.pins[7 - 1].value << 1; // RB1
PORTB |= pic1.pins[8 - 1].value << 2; // RB2
PORTB |= pic1.pins[9 - 1].value << 3; // RB3
PORTB |= pic1.pins[10 - 1].value << 4; // RB4
PORTB |= pic1.pins[11 - 1].value << 5; // RB5
PORTB |= pic1.pins[12 - 1].value << 6; // RB6
PORTB |= pic1.pins[13 - 1].value << 7; // RB7

if (PORTB != PORTB_old)
{
PORTB_old = PORTB;
printf("PORTB =0x%02X\n", PORTB);
}
}
}

void ctrlc_callback(int signum)
{
printf("end\n");
pic_end(&pic1);
exit(0);
}

int main()
{

pic_init(&pic1, getprocbyname("PIC16F628A"), "../../../examples/shift/shift.hex", 1, FREQ);

struct itimerval new_timer;
struct itimerval old_timer;

new_timer.it_value.tv_sec = 0;
new_timer.it_value.tv_usec = 100 * 1000; //100ms
new_timer.it_interval.tv_sec = 0;
new_timer.it_interval.tv_usec = 100 * 1000; //100ms

setitimer(ITIMER_REAL, &new_timer, &old_timer);
signal(SIGALRM, timer_callback);
signal(SIGINT, ctrlc_callback);

// Waitting forever
while (sleep(10))
;
}
3 changes: 0 additions & 3 deletions docs/examples/simple_use/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,5 @@ all: picsim_simple.c
clean:
rm -rf picsim_simple

run:
picsim_simple P16F628A ../../examples/shift.hex



Binary file removed docs/examples/simple_use/picsim_simple
Binary file not shown.
12 changes: 6 additions & 6 deletions docs/examples/simple_use/picsim_simple.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ int main()
_pic pic1;

//set serial port
pic_set_serial(&pic1,"/dev/tnt2",0,0,0);
pic_set_serial(&pic1,0, "/dev/tnt2",0,0,0);
//pic_set_serial(&pic1,"COM2",0,0,0);

//initialization and program loading
pic_init(&pic1, P16F628A, "../../../examples/shift/shift.hex",1,20e6);
pic_init(&pic1, getprocbyname("PIC16F628A"), "../../../examples/shift/shift.hex", 1, 4e6);

//enable print messages of internal instruction execution (slow down the simulation speed)
pic1.print=1;
Expand All @@ -22,13 +22,13 @@ int main()
for(i=0;i<1000;i++)
{
//execute one instruction cycle
pic_step();
pic_step(&pic1);
//read digital pin 1
val=pic_get_pin(1);
val=pic_get_pin(&pic1, 1);
//write digital pin 2
pic_set_pin(2, val);
pic_set_pin(&pic1, 2, val);
}

//free internal memory
pic_end();
pic_end(&pic1);
}

0 comments on commit 1ff7822

Please sign in to comment.