/***************************************************************************/ /* Das Programm zum Hochspannungsgerät */ /* -------------------------------------------------------------------- */ /* copyright (c) 2002 by Hubersoft Corp. All rights reserved. */ /***************************************************************************/ #include #include #include #include #include //#TARGET AT90S2313; ///////////////////////////////////////////////////////// // Hochspannungsgerät // // --------------------------------------- // // PORTB = Display Datenleitungen // // PORTD0 = Register select // // PORTD1 = Display enable // // PORTD2 = Taster 1 // // PORTD3 = Taster 2 // // PORTD4 = Taster 3 // // PORTD5 = Trafo Spule 1 // // PORTD6 = Trafo Spule 2 // ///////////////////////////////////////////////////////// /***********************************************************************************/ volatile unsigned char chfrequenz[17]="Frequenz: "; volatile unsigned char chleistung[17]="Leistung: "; volatile unsigned char vfrequenz=50; volatile unsigned char vleistung=10; volatile unsigned char displaymode=0; /***********************************************************************************/ void delay(unsigned int ms) //ms Millisekunden warten { register unsigned char a, b, c; for (a=ms; a>0; --a) for (b=27; b>0; --b) for (c=91; c>0; --c); } /***********************************************************************************/ void mdelay(unsigned int ms) //ms Mikrosekunden warten { register unsigned char a, b; for (a=ms; a>0; --a) for (b=7; b>0; --b); } /***********************************************************************************/ void wd(unsigned char data) { outp(data, PORTB); sbi(PORTD,0); sbi(PORTD,1); cbi(PORTD,1); delay(1); } /***********************************************************************************/ void wc(unsigned char command) { outp(command, PORTB); cbi(PORTD,0); sbi(PORTD,1); delay(1); cbi(PORTD,1); delay(1); } /***********************************************************************************/ void write(char text[]) { unsigned char i=0; wc(1); wc(128); while (*text) {if (i++==8) wc(192); wd(*text++);} } /***********************************************************************************/ void DisplayInit(void) { outp(0xff,DDRB); outp(0xff,DDRD); wc(0); //Init control lines wc(12); //Display on wc(1); // Display clear wc(56); // 8 bit bus } /***********************************************************************************/ void showvalue(void) { unsigned char i; chleistung[10]=(vleistung/100+48); chleistung[11]=((vleistung%100)/10+48); chleistung[12]=((vleistung%100)%10+48); chleistung[13]=37; chfrequenz[10]=((vfrequenz/100)+48); chfrequenz[11]=((vfrequenz%100)/10+48); chfrequenz[12]=((vfrequenz%100)%10+48); chfrequenz[13]=37; if (chleistung[10]==48) {chleistung[10]=32; if (chleistung[11]==48) chleistung[11]=32;} if (chfrequenz[10]==48) {chfrequenz[10]=32; if (chfrequenz[11]==48) chfrequenz[11]=32;} wc(128); if (displaymode) for(i=0;i<16;i++) {if (i==8) wc(192); wd(chfrequenz[i]);} else for(i=0;i<16;i++) {if (i==8) wc(192); wd(chleistung[i]);} } /***********************************************************************************/ void savesettings(void) { unsigned int i; cli(); for (i=0; i<30; i++) {while (!eeprom_is_ready()); eeprom_wb(i,vfrequenz);} for (i=30; i<60; i++) {while (!eeprom_is_ready()); eeprom_wb(i,vleistung);} for (i=60; i<90; i++) {while (!eeprom_is_ready()); eeprom_wb(i,displaymode);} sei(); } /***********************************************************************************/ void loadsettings(void) { unsigned char i; unsigned char temp[3]; cli(); temp[0]=0;temp[1]=1; for(i=0;i<30;i++) { temp[i%3]=eeprom_rb(i++); if ((temp[0]==temp[1])&&(temp[0]==temp[2])) vfrequenz=temp[0]; } temp[0]=0;temp[1]=1; for(i=0;i<30;i++) { temp[i%3]=eeprom_rb(30+(i++)); if ((temp[0]==temp[1])&&(temp[0]==temp[2])) vleistung=temp[0]; } temp[0]=0;temp[1]=1; for(i=0;i<30;i++) { temp[i%3]=eeprom_rb(60+(i++)); if ((temp[0]==temp[1])&&(temp[0]==temp[2])) displaymode=temp[0]; } if (displaymode>0) displaymode=1; if (vfrequenz>100) vfrequenz=50; if (vleistung>100) vleistung=50; sei(); } /***********************************************************************************/ SIGNAL(SIG_OVERFLOW0) { unsigned char w=1; cbi(PORTD,5); cbi(PORTD,6); if ((inp(PIND)&28)!=28) { if (!displaymode) { while ((inp(PIND)&4)==0) {if (w) {w=0; delay(100);} if (vleistung<100) vleistung++;showvalue(); delay(30);} while ((inp(PIND)&8)==0) {if (w) {w=0; delay(100);} if (vleistung>0) vleistung--;showvalue(); delay(30);} } else { while ((inp(PIND)&4)==0){if (w) {w=0; delay(100);} if (vfrequenz<100) vfrequenz++;showvalue(); delay(30);} while ((inp(PIND)&8)==0){if (w) {w=0; delay(100);} if (vfrequenz>0) vfrequenz--;showvalue(); delay(30);} } if ((inp(PIND)&16)==0) {displaymode=1-displaymode; showvalue(); while ((inp(PIND)&16)==0);} savesettings(); } } /***********************************************************************************/ unsigned int timeon=0; unsigned int timeoff=0; /***********************************************************************************/ void wait1(void) { unsigned char a; cli(); for(a=130;a>0;a--) delay(10); wc(1); } /***********************************************************************************/ int main( void ) { sbi(PORTD,2); //Taster 1 high sbi(PORTD,3); //Taster 2 high sbi(PORTD,4); //Taster 3 high cbi(PORTD,5); //Spule 1 aus cbi(PORTD,6); //Spule 2 aus loadsettings(); delay(100); DisplayInit(); if ((inp(PIND)&28)==0) for(;;) { write(" Hochspannungs"); wait1(); write(" Ger\xE1t"); wait1(); write("(c) 1998-2002 by"); wait1(); write("Hubersoft Corp."); wait1(); } outp(5, TCCR0); // Timer 0 prescaler 1024 outp(2, TIMSK); // Timer 0 overflow int enable (38.14697266) sei(); // Enable Interrupts showvalue(); for (;;) { while (vleistung==0) {cbi(PORTD,5);cbi(PORTD,6);} timeon=((vleistung)*(100-vfrequenz))/100; timeoff=((100-vleistung)*(100-vfrequenz))/100; cbi(PORTD,5); sbi(PORTD,6); mdelay(timeon); cbi(PORTD,5); cbi(PORTD,6); mdelay(timeoff); sbi(PORTD,5); cbi(PORTD,6); mdelay(timeon); cbi(PORTD,5); cbi(PORTD,6); mdelay(timeoff); } } //***********************************************************************************//