Most recent edit made on
2009-05-01 14:40:37 by cmantito
[start/stop works, it counts all four digits and works.]
Additions:
Port 3 - in/out - buttons & speaker & CPLD control
sbit outAcknowledge = P3^7; out
void setupInputs();
void digitsCallback();
void controlCallback();
int modeState = 0;
setupInputs();
runningLoop();
outDisplay = tenSecs + 64;
outDisplay = seconds + 128;
outDisplay = tenths + 192;
outDisplay = hunths + 0;
P2 = 0x00000000;
void setupInputs() {
IT0 = 1; Set on falling edge.
IT1 = 1; Set on falling edge.
EX0 = 1; Enable external interrupt 0.
EX1 = 1; Enable external interrupt 1.
modeState = 0;
outAcknowledge = 0;
INTERRUPT CALLBACKS
void digitsCallback() interrupt 0 {
if(modeState
0){
seconds = inDigits & 0x0f;
}else if(modeState
1){
tenSecs = inDigits & 0x0f;
}else if(modeState
2){
hunths = inDigits & 0x0f;
}else if(modeState
3){
tenths = inDigits & 0x0f;
if(modeState < 3){
modeState;
}else{
modeState = 0;
outAcknowledge = 1;
outAcknowledge = 0;
void controlCallback() interrupt 2 {
TR0 =~ TR0;
Deletions:
sbit outStartStop = P1^1;
we probably won't use this at all.
Port 3 - in/out - buttons & speaker
sbit btnReset = P3^2;
in
sbit btnLap = P3^4; in
sbit spkrTick = P3^5;
out
void buttonCallback();
int pulseCount = 0;
runningLoop();
if(pulseCount
0){
hunths = inDigits;
pulseCount;
}else if(pulseCount
1){
tenths = inDigits;
pulseCount;
}else if(pulseCount
2){
seconds = inDigits;
pulseCount;
}else if(pulseCount
3){
tenSecs = inDigits;
pulseCount = 0;
}
outDisplay = seconds;
void buttonCallback() {
Edited on
2009-04-01 13:12:24 by cmantito
[More test code. Timer is a bit quick, but overall roughly right.]
Additions:
Edited on
2009-04-01 12:09:15 by cmantito
[C in a test mode to count/disp secs only, pulsing is still 40ms.]
Additions:
#define inDigits P0
#define outDisplay P2
while(1){
if(pulseCount
0){
hunths = inDigits;
pulseCount;
}else if(pulseCount
1){
tenths = inDigits;
pulseCount;
}else if(pulseCount
2){
seconds = inDigits;
pulseCount;
}else if(pulseCount
3){
tenSecs = inDigits;
pulseCount = 0;
}
outDisplay = seconds;
Deletions:
sbit inDigits = P0;
sbit outDisplay = P2;
while(1);
if(pulseCount
0){
hunths = P0;
pulseCount;
}else if(pulseCount
1){
tenths = P0;
pulseCount;
}else if(pulseCount
2){
seconds = P0;
pulseCount;
}else if(pulseCount
3){
tenSecs = P0;
pulseCount = 0;
Edited on
2009-03-25 12:58:40 by cmantito
[added resetCPLD() so reset != 1 constantly. burned to chip.]
Additions:
sbit outReset = P1^1;
sbit outStartStop = P1^1;
we probably won't use this at all.
void resetCPLD();
resetCPLD();
void resetCPLD(){
outReset = 1;
outReset = 0;
Deletions:
sbit outStartStop = P1^1;
sbit outReset = P1^2;
Additions:
Deletions:
Additions:
void buttonCallback();
}else if(pulseCount
3){
void buttonCallback() {
Deletions:
void processButtons();
void processClock();
processButtons();
processClock();
}else if(pulsecount
3){
Edited on
2009-03-18 14:05:23 by cmantito
[Added variables/fixed signals, added multiplexing code. Added clock.]
Additions:
sbit inDigits = P0;
sbit outDisplay = P2;
/
DECLARE VARIABLES
/
int pulseCount = 0;
unsigned char hunths, tenths, seconds, tenSecs;
if(pulseCount
0){
hunths = P0;
pulseCount;
}else if(pulseCount
1){
tenths = P0;
pulseCount;
}else if(pulseCount
2){
seconds = P0;
pulseCount;
}else if(pulsecount
3){
tenSecs = P0;
pulseCount = 0;
}
Deletions:
sbit inClockA = P0^1;
sbit inClockB = P0^2;
sbit modeSigA = P0^6;
sbit modeSigB = P0^7;
sbit outDigits = P2;
sbit digitSelectA = P2^6;
sbit digitSelectB = P2^7;
Additions:
Additions:
/
DECLARE SUBROUTINES
/
void setupTimer();
void runningLoop();
void timerCallback();
void processButtons();
void processClock();
void main() {
setupTimer();
runningLoop();
}
void runningLoop() {
processButtons();
processClock();
while(1);
}
void setupTimer() {
TMOD = 0x01; M0 = 1 (Timer mode 1 - 16 bit mode)
TL0 = 0xFF; 400Hz = 2304 delay count, 65535-2304 = 63231
TH0 = 0xF6; TH0 = 0xF6 :: TL0(0xFF) = 0xF6FF = 63231
ET0 = 1; T0 Interrupt enabled.
EA = 1; Interrupts enabled.
TR0 = 1; Begin timer.
return;
}
void timerCallback() interrupt 1 using 2 {
outClock =~ outClock; Invert the clock output pin.
}
Additions:
/
PIN DEFINITIONS
/
Port 0 - in - in from CPLD
sbit inClockA = P0^1;
sbit inClockB = P0^2;
sbit modeSigA = P0^6;
sbit modeSigB = P0^7;
Port 1 - all out - out to CPLD
sbit outClock = P1^0;
sbit outStartStop = P1^1;
sbit outReset = P1^2;
Port 2 - all out - out to display
sbit outDigits = P2;
sbit digitSelectA = P2^6;
sbit digitSelectB = P2^7;
Port 3 - in/out - buttons & speaker
sbit btnReset = P3^2; in
sbit btnStartStop = P3^3; in
sbit btnLap = P3^4; in
sbit spkrTick = P3^5; out
PROGRAMME CODE
Deletions:
#define on 1
#define off 2
#include <reg66x.h>
#define on 1
#define off 2
Categories:
CategoryUni