Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rework lights for FX2LP CY7C68013A mini boards #29

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions examples/bulkloop/bulkloop.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ void main() {
printf ( "Done initializing stuff\n" );


d3off();
d1off();

while(TRUE) {

Expand Down Expand Up @@ -204,13 +204,13 @@ void sudav_isr() __interrupt SUDAV_ISR {
CLEAR_SUDAV();
}

__bit on5;
__bit on2;
__xdata WORD sofct=0;
void sof_isr () __interrupt SOF_ISR __using 1 {
++sofct;
if(sofct==8000) { // about 8000 sof interrupts per second at high speed
on5=!on5;
if (on5) {d5on();} else {d5off();}
on2=!on2;
if (on2) {d2on();} else {d2off();}
sofct=0;
}
CLEAR_SOF();
Expand Down
12 changes: 6 additions & 6 deletions examples/debugdevice/debugdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ void main()
printf ( "USB DEBUG: Done initializing stuff\n" );


d3off();
d1off();

while(TRUE) {

Expand Down Expand Up @@ -207,16 +207,16 @@ void sudav_isr() __interrupt SUDAV_ISR {
CLEAR_SUDAV();
}

__bit on5;
__bit on2;
__xdata WORD sofct=0;
void sof_isr () __interrupt SOF_ISR __using 1
{
if(++sofct==8000) { // about 8000 sof __interrupts per second at high speed
on5 = !on5;
if (on5) {
d5on();
on2 = !on2;
if (on2) {
d2on();
} else {
d5off();
d2off();
}
sofct=0;
}
Expand Down
23 changes: 14 additions & 9 deletions examples/lights/lights.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,22 @@
#include <lights.h>
#include <delay.h>

volatile __xdata BYTE* bytes[] = { &D2ON, &D3ON, &D4ON, &D5ON, &D2OFF, &D3OFF, &D4OFF, &D5OFF };

void main(void)
{
volatile BYTE tmp;
BYTE cur=0;
BYTE n = 0;

// loop endlessly
for(;;) {
tmp=*bytes[cur];
delay(50);
cur = cur == 7 ? 0 : cur+1;
init_lights();
for (;;) {
if (n == 0) {
d1on();
} else if (n == 1) {
d2on();
} else if (n == 2) {
d1off();
} else {
d2off();
}
delay(250);
n = (n + 1) % 4;
}
}
3 changes: 2 additions & 1 deletion examples/reset/reset.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,10 @@ void main() {
eeprom_write_local(LG_PROM, 0, IIC_SIZE, fx2_c0);


init_lights();
while (1) {
delay(1000);
if (on) {d5on();} else {d5off();}
if (on) {d1on();} else {d1off();}
on = !on;
}

Expand Down
2 changes: 1 addition & 1 deletion examples/serial/serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ void main(void)
TR1=1; // start timer 1


d5off(); // end init
d1off(); // end init

while (1) {
char r=getchar();
Expand Down
20 changes: 7 additions & 13 deletions examples/timers/timers.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,24 @@
#include <fx2ints.h>
#include <lights.h>

volatile __bit d1;
volatile __bit d2;
volatile __bit d3;
volatile __bit d4;
volatile __bit d5;

void timer0_isr() __interrupt TF0_ISR {
d2 = !d2;
if (d2) { d2on(); } else { d2off(); }
d1 = !d1;
if (d1) { d1on(); } else { d1off(); }
}

void timer1_isr() __interrupt TF1_ISR {
d3 = !d3;
if (d3) { d3on(); } else { d3off(); }
d2 = !d2;
if (d2) { d2on(); } else { d2off(); }
}

void timer2_isr() __interrupt TF2_ISR {
d4 = !d4;
if (d4) { d4on(); } else { d4off(); }
d3 = !d3;
if (d3) { d1on(); d2on(); } else { d1off(); d2off(); }

CLEAR_TIMER2(); // This one is not done automatically!
}
Expand Down Expand Up @@ -66,13 +66,7 @@ void main(void)
TR1=1; // start t1
TR2=1; // start t2

// and blink d5
while (TRUE) {
++counter;
if (!counter) {
d5 = !d5;
if (d5) { d5off(); } else { d5on(); }
}
}
}

Expand Down
72 changes: 5 additions & 67 deletions include/lights.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,74 +23,12 @@

#include "fx2types.h"

#ifndef FX1
// FX2 Dev board lights
#define D2ONH #0x88 // assembly high byte of light addr
#define D2OFFH #0x80
#define D3ONH #0x98
#define D3OFFH #0x90
#define D4ONH #0xA8
#define D4OFFH #0xA0
#define D5ONH #0xB8
#define D5OFFH #0xB0
volatile __xdata __at 0x8800 BYTE D2ON;
volatile __xdata __at 0x8000 BYTE D2OFF;
volatile __xdata __at 0x9800 BYTE D3ON;
volatile __xdata __at 0x9000 BYTE D3OFF;
volatile __xdata __at 0xA800 BYTE D4ON;
volatile __xdata __at 0xA000 BYTE D4OFF;
volatile __xdata __at 0xB800 BYTE D5ON;
volatile __xdata __at 0xB000 BYTE D5OFF;
#else
// FX1 dev board lights
#define D2ONH #0x80 // assembly high byte of light addr
#define D2OFFH #0x81
#define D3ONH #0x90
#define D3OFFH #0x91
#define D4ONH #0xA0
#define D4OFFH #0xA1
#define D5ONH #0xB0
#define D5OFFH #0xB1
volatile __xdata __at 0x8000 BYTE D2ON;
volatile __xdata __at 0x8100 BYTE D2OFF;
volatile __xdata __at 0x9000 BYTE D3ON;
volatile __xdata __at 0x9100 BYTE D3OFF;
volatile __xdata __at 0xA000 BYTE D4ON;
volatile __xdata __at 0xA100 BYTE D4OFF;
volatile __xdata __at 0xB000 BYTE D5ON;
volatile __xdata __at 0xB100 BYTE D5OFF;
#endif
#define init_lights() IFCONFIG &= ~3; PORTACFG = 0x00

/**
* Easier to use macros defined below
**/
#define activate_light(LIGHT_ADDR) __asm \
mov __XPAGE, LIGHT_ADDR \
__endasm; __asm \
movx a, @r0 \
__endasm \
#define d1on() OEA |= 0x01; IOA &= ~0x01
#define d2on() OEA |= 0x02; IOA &= ~0x02

/**
* Easy to make lights blink with these macros:
* \code
* WORD ct=0;
* BOOL on=FALSE;
* while (TRUE) {
* if (!ct) {
* on=!on;
* if (on) d2on(); else d2off();
* }
* ++ct;
* }
* \endcode
**/
#define d2on() activate_light(D2ONH)
#define d2off() activate_light(D2OFFH)
#define d3on() activate_light(D3ONH)
#define d3off() activate_light(D3OFFH)
#define d4on() activate_light(D4ONH)
#define d4off() activate_light(D4OFFH)
#define d5on() activate_light(D5ONH)
#define d5off() activate_light(D5OFFH)
#define d1off() OEA |= 0x01; IOA |= 0x01
#define d2off() OEA |= 0x02; IOA |= 0x02

#endif