Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

numbers mapped, save and recover ffrom power off seem to work

  • Loading branch information...
commit 8604229f4b1e8020c7382ddeffefe45690aba64a 1 parent e97eb43
@raphaelabrams authored
Showing with 85 additions and 88 deletions.
  1. +85 −88 freelance_puncher.X/puncher.c
View
173 freelance_puncher.X/puncher.c
@@ -20,12 +20,8 @@
#define START_M 0
#define START_S 55
-//unsigned char* memcpyee(unsigned char to, const void *from, unsigned char size);
-//unsigned char* eecpymem(unsigned char *to, unsigned char from, unsigned char size);
-
-//unsigned char eeprom_read(unsigned char addr);
-//void eeprom_write(unsigned char addr, unsigned char value);
void init(void);
+void display(char left, char right, char stack);
//call the following twice (with different args each time) and the compiler automatically sets each config register
__CONFIG(FOSC_LP & WDTE_OFF & PWRTE_ON & MCLRE_ON & CP_OFF & CPD_OFF & BOREN_ON & FCMEN_OFF);
@@ -38,57 +34,107 @@ near unsigned char centons; //hee hee 100 hours!
near unsigned char hours;
near unsigned char minutes;
near unsigned char seconds;
-
-const unsigned char led[] = {1,2,4,8,16,32,64,128};
+near unsigned char ticks;
+
+const unsigned char led[] = {
+ 0b11111100,
+ 0b01100000,
+ 0b11011010,
+ 0b11110010,
+ 0b01100110,
+
+ 0b10110110,
+ 0b10111110,
+ 0b11100000,
+ 0b11111110,
+ 0b11110110
+};
const unsigned char common[] ={1,2,4};
+void display(char left, char right, char stack){
+ LATB = ~led[left];
+ LATA = common[2];
+ LATA = 0;
+
+ LATB = ~led[right];
+ LATA = common[1];
+ LATA = 0;
+
+ LATB = stack;
+ LATA = common[0];
+ LATA = 0;
+}
+
void main(void){
init();
newSecond = tickCounter = 0;
seconds=eeprom_read(0);
minutes=eeprom_read(1);
+ hours=eeprom_read(2);
+ centons=eeprom_read(3);
// Initialise the current time
// Measure time
+
while(1){
-// if(RA4==0){
- // LATA=0b00000001;
- // LATB=0xFD;
-// while(RA4==0){;}
- // }else{LATA=0b00000010;}
-// if(RA3==0){
- // centons=START_C;
- // hours = START_H;
- // minutes = START_M;
- // seconds = START_S;
- // }
- if(newSecond){
- LATB = ~led[seconds%8];
- LATA = common[minutes%3];
+ LATB = ~led[seconds/10]; //left
+ LATA = common[2];
+ LATA = common[2];
+ LATA = common[2];
+ LATA = 0;
+
+ LATB = ~led[seconds%10]; //right
+ LATA = common[1];
+ LATA = common[1];
+ LATA = common[1];
+ LATA = 0;
+
+ LATB = ~seconds; //stack
+ LATA = common[0];
+ LATA = common[0];
+ LATA = common[0];
+ LATA = 0;
+// display(seconds/10,seconds%10,~seconds);
+ if(RA4==0){
+ PIE1 = 0b00000000;
+
+ LATA=0b00000110;
+ LATB=0b11111110;
eeprom_write(0, seconds);
eeprom_write(1, minutes);
+ eeprom_write(2, hours);
+ eeprom_write(3, centons);
+ while(RA4==0){;}
+ }
+ if(RA3==0){
+ centons=START_C;
+ hours = START_H;
+ minutes = START_M;
+ seconds = START_S;
+ }
+ if(newSecond){
// A second has accumulated, count it
newSecond=0;
if(++seconds > 59){
seconds=0;
minutes++;
-// EEPROM_WRITE(0, seconds);
- // EEPROM_WRITE(1, minutes);
// LATA = common[minutes%3];
if(++minutes > 59){
minutes = 0;
hours++;
- // EEPROM_WRITE(2, hours);
+ eeprom_write(0, seconds);
+ eeprom_write(1, minutes);
+ eeprom_write(2, hours);
+ eeprom_write(3, centons);
if(hours>99){
centons++;
- // EEPROM_WRITE(3, centons);
hours=0;
}
}
@@ -99,11 +145,16 @@ void main(void){
void interrupt isr(void){
/***** Timer 2 Code *****/
- if((TMR2IE)&&(TMR2IF)){
+// if((TMR2IE)&&(TMR2IF)){
// Interrupt period is 40 mSec, 25 interrupts = 1 Sec
- newSecond++; // Notify a second has accumulated
- TMR2IF=0; // clear event flag
- }
+// ticks++;
+// if(ticks==32){newSecond++;ticks=0;} // Notify a second has accumulated
+ newSecond++;
+ // display(seconds%10,seconds%10,seconds);
+
+// }
+ TMR2IF=0; // clear event flag
+
}
void init(void){
@@ -111,7 +162,10 @@ void init(void){
* Timer 2 interrupt enabled.
*/
PIE1 = 0b00000010;
- /*
+ ANSELA=0;
+ ANSELB=0;
+
+ /*
* Peripheral interrupts enabled
* Global interrupt disabled during initialization
*/
@@ -130,62 +184,5 @@ void init(void){
TRISB=0;
TRISA=0b11111000;
LATA=0b00000110;
- LATB=0;
+ LATB=0b11111101;
}
-
-
-
-
-
-//void eeprom_write(unsigned char addr, unsigned char value){
-// EEPROM_WRITE(addr, value);
-//}
-
-
-
-//unsigned char eeprom_read(unsigned char addr){
-// while (WR) continue;
-// return EEPROM_READ(addr);
-//}
-/*
-unsigned char* eecpymem(unsigned char *to, unsigned char from, unsigned char size){
- unsigned char *cp = to;
-
- while (WR) continue;
- EEADRL = (unsigned char)from;
- while(size--) {
- while (WR) continue;
- #ifdef __FLASHTYPE
- EECON1 &= 0x7F;
- #endif
- RD = 1;
- *cp++ = EEDATA;
- ++EEADRL;
- }
- return to;
-}
-
-unsigned char* memcpyee(unsigned char to, const void *from, unsigned char size){
-
- const unsigned char *ptr =from;
- while (WR) continue;
- EEADRL = (unsigned char)to - 1;
- #ifdef __FLASHTYPE
- EECON1 &= 0x7F;
- #endif
- while(size--) {
- while (WR) continue;
- EEDATA = *ptr++;
- ++EEADRL;
- CARRY = 0; if (GIE) CARRY = 1; GIE = 0;
- WREN = 1;
- EECON2 = 0x55;
- EECON2 = 0xAA;
- WR = 1;
- WREN = 0;
- if (CARRY) GIE = 1; //an opportunity for interrupts to happen
- }
- return (unsigned char *)to;
-}
-
-*/
Please sign in to comment.
Something went wrong with that request. Please try again.