//video scope -- Circuit Cellar Version //D.5 is sync:1000 ohm + diode to 75 ohm resistor //D.6 is video:330 ohm + diode to 75 ohm resistor #pragma regalloc- //I allocate the registers myself #pragma optsize- //optimize for speed #include #include #include #include #include //cycles = 63.625 * 16 Note that normal NTSC is 63.55 //but this line duration makes each frame exactly 1/60 sec //which is nice for keeping a realtime clock #define lineTime 1018 #define begin { #define end } #define ScreenTop 30 #define ScreenBot 210 //NOTE that v1 to v8 and i must be in registers! //These registers contain the current line to be //blasted to the screen register char v1 @4; register char v2 @5; register char v3 @6; register char v4 @7; register char v5 @8; register char v6 @9; register char v7 @10; register char v8 @11; register int i @12; #pragma regalloc+ //video stuff char syncON, syncOFF; //current line int LineCount; //voltage trace and last one char ADout[128], ADold[128]; // current voltage sample and previous one char ADnow, ADlast; //ii counts current trace length //jj counts sample skipping //k counts trace drawing char ii,jj,k; //trigger variables //level, arm flag, run/stop flag char trigLevel, oneShotarm, oneShotenable; char trigmode ; // time scale -- factors of 2 from 8 ms/screen to about 1000 char tscale; // number of samples-1 to skip for each time scale char tscalemask[]={0,1,3,7,15,31,63,127} ; // actual time scale value char tscaleV[]={1,2,4,8,16,32,64,128}; float tscalefull[]={8., 16., 33., 65., 130., 261., 521., 1042.}; //button state machine //sample rate for buttons, machine state 0-3, actual button data char bstep, bstate, buttons; //voltage bit scale, zero pt on screen, actual point on screen //voltage scale char vscale, vzero, vpoint,vselect; //summing variable for average calculation //long rmss ; //int rms ; //char rmsss[]="RMS V"; //The actual screen image char screen[90*16], //Utility string vs[10]; //All the strings char cu1[]="NS"; char tlev[]="TLEVL" ; char tlevel[]="LEVL", text[]="STIM", tfree[]="FREE"; char trun[]="RUN", tstop[]="STP", tarm[]="ARM"; char blanks[]=" "; char param[8][5]={"HORZ","VERT","CURS","TMOD", "TLVL","AMP ","DUR ","SPAC"} ; char srept[]="REP", soff[]="OFF", sone[]="ONE", stwo[]="TWO"; //current parameter to set char currentSet; //Pulse gen variables int PulseSpacing, PulseDuration; int PulseCount ; //mode can be repeat/single/off rep/one/off // singlepulse allows exactly one pulse char PulseAmp, PulseMode, SinglePulse ; //cursor position char curx ; //Point plot lookup table flash char pos[8]={0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01}; //define some character bitmaps //5x7 characters flash char bitmap[38][7]={ //0 0b01110000, 0b10001000, 0b10011000, 0b10101000, 0b11001000, 0b10001000, 0b01110000, //1 0b00100000, 0b01100000, 0b00100000, 0b00100000, 0b00100000, 0b00100000, 0b01110000, //2 0b01110000, 0b10001000, 0b00001000, 0b00010000, 0b00100000, 0b01000000, 0b11111000, //3 0b11111000, 0b00010000, 0b00100000, 0b00010000, 0b00001000, 0b10001000, 0b01110000, //4 0b00010000, 0b00110000, 0b01010000, 0b10010000, 0b11111000, 0b00010000, 0b00010000, //5 0b11111000, 0b10000000, 0b11110000, 0b00001000, 0b00001000, 0b10001000, 0b01110000, //6 0b01000000, 0b10000000, 0b10000000, 0b11110000, 0b10001000, 0b10001000, 0b01110000, //7 0b11111000, 0b00001000, 0b00010000, 0b00100000, 0b01000000, 0b10000000, 0b10000000, //8 0b01110000, 0b10001000, 0b10001000, 0b01110000, 0b10001000, 0b10001000, 0b01110000, //9 0b01110000, 0b10001000, 0b10001000, 0b01111000, 0b00001000, 0b00001000, 0b00010000, //A 0b01110000, 0b10001000, 0b10001000, 0b10001000, 0b11111000, 0b10001000, 0b10001000, //B 0b11110000, 0b10001000, 0b10001000, 0b11110000, 0b10001000, 0b10001000, 0b11110000, //C 0b01110000, 0b10001000, 0b10000000, 0b10000000, 0b10000000, 0b10001000, 0b01110000, //D 0b11110000, 0b10001000, 0b10001000, 0b10001000, 0b10001000, 0b10001000, 0b11110000, //E 0b11111000, 0b10000000, 0b10000000, 0b11111000, 0b10000000, 0b10000000, 0b11111000, //F 0b11111000, 0b10000000, 0b10000000, 0b11111000, 0b10000000, 0b10000000, 0b10000000, //G 0b01110000, 0b10001000, 0b10000000, 0b10011000, 0b10001000, 0b10001000, 0b01110000, //H 0b10001000, 0b10001000, 0b10001000, 0b11111000, 0b10001000, 0b10001000, 0b10001000, //I 0b01110000, 0b00100000, 0b00100000, 0b00100000, 0b00100000, 0b00100000, 0b01110000, //J 0b00111000, 0b00010000, 0b00010000, 0b00010000, 0b00010000, 0b10010000, 0b01100000, //K 0b10001000, 0b10010000, 0b10100000, 0b11000000, 0b10100000, 0b10010000, 0b10001000, //L 0b10000000, 0b10000000, 0b10000000, 0b10000000, 0b10000000, 0b10000000, 0b11111000, //M 0b10001000, 0b11011000, 0b10101000, 0b10101000, 0b10001000, 0b10001000, 0b10001000, /*N 0b10001000, 0b10001000, 0b11001000, 0b10101000, 0b10011000, 0b10001000, 0b10001000, */ //Nu 0b00000000, 0b00000000, 0b11001000, 0b00101000, 0b00101000, 0b00011000, 0b00010000, //O 0b01110000, 0b10001000, 0b10001000, 0b10001000, 0b10001000, 0b10001000, 0b01110000, //P 0b11110000, 0b10001000, 0b10001000, 0b11110000, 0b10000000, 0b10000000, 0b10000000, //Q 0b01110000, 0b10001000, 0b10001000, 0b10001000, 0b10101000, 0b10010000, 0b01101000, //R 0b11110000, 0b10001000, 0b10001000, 0b11110000, 0b10100000, 0b10010000, 0b10001000, //S 0b01111000, 0b10000000, 0b10000000, 0b01110000, 0b00001000, 0b00001000, 0b11110000, //T 0b11111000, 0b00100000, 0b00100000, 0b00100000, 0b00100000, 0b00100000, 0b00100000, //U 0b10001000, 0b10001000, 0b10001000, 0b10001000, 0b10001000, 0b10001000, 0b01110000, //V 0b10001000, 0b10001000, 0b10001000, 0b10001000, 0b10001000, 0b01010000, 0b00100000, //W 0b10001000, 0b10001000, 0b10001000, 0b10101000, 0b10101000, 0b10101000, 0b01010000, //X 0b10001000, 0b10001000, 0b01010000, 0b00100000, 0b01010000, 0b10001000, 0b10001000, //Y 0b10001000, 0b10001000, 0b10001000, 0b01010000, 0b00100000, 0b00100000, 0b00100000, //Z 0b11111000, 0b00001000, 0b00010000, 0b00100000, 0b01000000, 0b10000000, 0b11111000, //figure1 0b01110000, 0b00100000, 0b01110000, 0b10101000, 0b00100000, 0b01010000, 0b10001000, //figure2 0b01110000, 0b10101000, 0b01110000, 0b00100000, 0b00100000, 0b01010000, 0b10001000}; //================================ //3x5 font numbers, then letters //packed two per definition for fast //copy to the screen at x-position divisible by 4 flash char smallbitmap[39][5]={ //0 0b11101110, 0b10101010, 0b10101010, 0b10101010, 0b11101110, //1 0b01000100, 0b11001100, 0b01000100, 0b01000100, 0b11101110, //2 0b11101110, 0b00100010, 0b11101110, 0b10001000, 0b11101110, //3 0b11101110, 0b00100010, 0b11101110, 0b00100010, 0b11101110, //4 0b10101010, 0b10101010, 0b11101110, 0b00100010, 0b00100010, //5 0b11101110, 0b10001000, 0b11101110, 0b00100010, 0b11101110, //6 0b11001100, 0b10001000, 0b11101110, 0b10101010, 0b11101110, //7 0b11101110, 0b00100010, 0b01000100, 0b10001000, 0b10001000, //8 0b11101110, 0b10101010, 0b11101110, 0b10101010, 0b11101110, //9 0b11101110, 0b10101010, 0b11101110, 0b00100010, 0b01100110, //. 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b11001100, //- 0b00000000, 0b00000000, 0b11101110, 0b00000000, 0b00000000, //blank 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, //A 0b11101110, 0b10101010, 0b11101110, 0b10101010, 0b10101010, //B 0b11001100, 0b10101010, 0b11101110, 0b10101010, 0b11001100, //C 0b11101110, 0b10001000, 0b10001000, 0b10001000, 0b11101110, //D 0b11001100, 0b10101010, 0b10101010, 0b10101010, 0b11001100, //E 0b11101110, 0b10001000, 0b11101110, 0b10001000, 0b11101110, //F 0b11101110, 0b10001000, 0b11101110, 0b10001000, 0b10001000, //G 0b11101110, 0b10001000, 0b10001000, 0b10101010, 0b11101110, //H 0b10101010, 0b10101010, 0b11101110, 0b10101010, 0b10101010, //I 0b11101110, 0b01000100, 0b01000100, 0b01000100, 0b11101110, //J 0b00100010, 0b00100010, 0b00100010, 0b10101010, 0b11101110, //K 0b10001000, 0b10101010, 0b11001100, 0b11001100, 0b10101010, //L 0b10001000, 0b10001000, 0b10001000, 0b10001000, 0b11101110, //M 0b10101010, 0b11101110, 0b11101110, 0b10101010, 0b10101010, //N 0b00000000, 0b11001100, 0b10101010, 0b10101010, 0b10101010, //O 0b01000100, 0b10101010, 0b10101010, 0b10101010, 0b01000100, //P 0b11101110, 0b10101010, 0b11101110, 0b10001000, 0b10001000, //Q 0b01000100, 0b10101010, 0b10101010, 0b11101110, 0b01100110, //R 0b11101110, 0b10101010, 0b11001100, 0b11101110, 0b10101010, //S 0b11101110, 0b10001000, 0b11101110, 0b00100010, 0b11101110, //T 0b11101110, 0b01000100, 0b01000100, 0b01000100, 0b01000100, //U 0b10101010, 0b10101010, 0b10101010, 0b10101010, 0b11101110, //V 0b10101010, 0b10101010, 0b10101010, 0b10101010, 0b01000100, //W 0b10101010, 0b10101010, 0b11101110, 0b11101110, 0b10101010, //X 0b00000000, 0b10101010, 0b01000100, 0b01000100, 0b10101010, //Y 0b10101010, 0b10101010, 0b01000100, 0b01000100, 0b01000100, //Z 0b11101110, 0b00100010, 0b01000100, 0b10001000, 0b11101110 }; //================================== //This is the sync generator and raster generator. It MUST be entered from //sleep mode to get accurate timing of the sync pulses #pragma warn- interrupt [TIM1_COMPA] void t1_cmpA(void) begin //start the Horizontal sync pulse PORTD = syncON; //count timer 0 at 1/usec TCNT0=0; //update the curent scanline number LineCount ++ ; //begin inverted (Vertical) synch after line 247 if (LineCount==248) begin syncON = 0b00100000; syncOFF = 0; end //back to regular sync after line 250 if (LineCount==251) begin syncON = 0; syncOFF = 0b00100000; end //start new frame after line 262 if (LineCount==263) begin LineCount = 1; end //delay_us(2); //adjust to make 5 us pulses //end sync pulse PORTD = syncOFF; //read A/D and restart it ADnow = ADCH ; ADCSR.6 = 1 ; //Make the output pulse (if any) //But first equalize times /* if (PulseMode==0) begin #asm nop nop nop nop nop #endasm end */ if (SinglePulse>0)PulseCount++; //PulseMode>0 && else PulseCount=PulseCount; //balance the conditional if (PulseCount<=PulseDuration && SinglePulse>0 ) PORTC=PulseAmp; else begin PORTC=0; #asm nop nop nop nop nop #endasm end //If the line is a display line, put it on the screen if (LineCount=ScreenTop) begin //compute byte index for beginning of the next line //left-shift 4 would be individual lines // <<3 means line-double the pixels //The 0xfff8 truncates the odd line bit //i=(LineCount-ScreenTop)<<3 & 0xfff8; // #asm push r16 lds r12, _LineCount lds r13, _Linecount+1 ldi r16, 30 sub r12, r16 ldi r16,0 sbc r13, r16 lsl r12 rol r13 lsl r12 rol r13 lsl r12 rol r13 mov r16,r12 andi r16,0xf0 mov r12,r16 pop r16 #endasm //load 16 registers with screen info #asm push r14 push r15 push r16 push r17 push r18 push r19 push r26 push r27 ldi r26,low(_screen) ;base address of screen ldi r27,high(_screen) add r26,r12 ;offset into screen (add i) adc r27,r13 ld r4,x+ ;load 16 registers and inc pointer ld r5,x+ ld r6,x+ ld r7,x+ ld r8,x+ ld r9,x+ ld r10,x+ ld r11,x+ ld r12,x+ ld r13,x+ ld r14,x+ ld r15,x+ ld r16,x+ ld r17,x+ ld r18,x+ ld r19,x pop r27 pop r26 #endasm //delay_us(1); //adjust to center image on screen //blast 16 bytes to the screen #asm ;but first a macro to make the code shorter ;the macro takes a register number as a parameter ;and dumps its bits serially to portD.6 ;the nop can be eliminated to make the display narrower .macro videobits ;regnum BST @0,7 IN R30,0x12 BLD R30,6 nop OUT 0x12,R30 BST @0,6 IN R30,0x12 BLD R30,6 nop OUT 0x12,R30 BST @0,5 IN R30,0x12 BLD R30,6 nop OUT 0x12,R30 BST @0,4 IN R30,0x12 BLD R30,6 nop OUT 0x12,R30 BST @0,3 IN R30,0x12 BLD R30,6 nop OUT 0x12,R30 BST @0,2 IN R30,0x12 BLD R30,6 nop OUT 0x12,R30 BST @0,1 IN R30,0x12 BLD R30,6 nop OUT 0x12,R30 BST @0,0 IN R30,0x12 BLD R30,6 nop OUT 0x12,R30 .endm videobits r4 ;video line -- byte 1 videobits r5 ;byte 2 videobits r6 ;byte 3 videobits r7 ;byte 4 videobits r8 ;byte 5 videobits r9 ;byte 6 videobits r10 ;byte 7 videobits r11 ;byte 8 videobits r12 ;byte 9 videobits r13 ;byte 10 videobits r14 ;byte 11 videobits r15 ;byte 12 videobits r16 ;byte 13 videobits r17 ;byte 14 videobits r18 ;byte 15 videobits r19 ;byte 16 clt ;clear video after the last pixel on the line IN R30,0x12 BLD R30,6 OUT 0x12,R30 pop r19 pop r18 pop r17 pop r16 pop r15 pop r14 #endasm end //of bit-blast to screen if (PulseCount==PulseSpacing && SinglePulse>0) begin // PORTC=0; PulseCount=0; if (PulseMode!=2) begin SinglePulse--; PulseCount=1; end end //check for trigger conditions if ((((ADnow==trigLevel) && (ADnow>ADlast) && (trigmode==0)) || (trigmode==1) || (PulseCount==0 && (trigmode==2))) && ii==129 ) ii=0; //save last sample ADlast = ADnow; //if triggered, then get waveform //set the time scale by skipping samples jj = ++jj & tscalemask[tscale] ; if (ii<128 && !jj) begin ADout[ii++] = ADnow ; end end #pragma warn+ //================================== //plot one point //at x,y with color 1=white 0=black 2=invert #pragma warn- void video_pt(char x, char y, char c) begin #asm ; i=(x>>3) + ((int)y<<4) ; the byte with the pixel in it push r16 ldd r30,y+2 ;get x lsr r30 lsr r30 lsr r30 ;divide x by 8 ldd r12,y+1 ;get y lsl r12 ;mult y by 16 clr r13 lsl r12 rol r13 lsl r12 rol r13 lsl r12 rol r13 add r12, r30 ;add in x/8 ;v2 = screen[i]; r5 ;v3 = pos[x & 7]; r6 ;v4 = c r7 ldi r30,low(_screen) ldi r31,high(_screen) add r30, r12 adc r31, r13 ld r5,Z ;get screen byte ldd r26,y+2 ;get x ldi r27,0 andi r26,0x07 ;form x & 7 ldi r30,low(_pos*2) ldi r31,high(_pos*2) add r30,r26 adc r31,r27 lpm r6,Z ld r16,y ;get c ;if (v4==1) screen[i] = v2 | v3 ; ;if (v4==0) screen[i] = v2 & ~v3; ;if (v4==2) screen[i] = v2 ^ v3 ; cpi r16,1 brne tst0 or r5,r6 tst0: cpi r16,0 brne tst2 com r6 and r5,r6 tst2: cpi r16,2 brne writescrn eor r5,r6 writescrn: ldi r30,low(_screen) ldi r31,high(_screen) add r30, r12 adc r31, r13 st Z, r5 ;write the byte back to the screen pop r16 #endasm end #pragma warn+ //================================== // put a big character on the screen // c is index into bitmap void video_putchar(char x, char y, char c) begin v7 = x; for (v6=0;v6<7;v6++) begin v1 = bitmap[c][v6]; v8 = y+v6; video_pt(v7, v8, (v1 & 0x80)==0x80); video_pt(v7+1, v8, (v1 & 0x40)==0x40); video_pt(v7+2, v8, (v1 & 0x20)==0x20); video_pt(v7+3, v8, (v1 & 0x10)==0x10); video_pt(v7+4, v8, (v1 & 0x08)==0x08); end end //================================== // put a string of big characters on the screen void video_puts(char x, char y, char *str) begin char i ; for (i=0; str[i]!=0; i++) begin if (str[i]>=0x30 && str[i]<=0x3a) video_putchar(x,y,str[i]-0x30); else video_putchar(x,y,str[i]-0x40+9); x = x+6; end end //================================== // put a small character on the screen // x-cood must be on divisible by 4 // c is index into bitmap void video_smallchar(char x, char y, char c) begin char mask; i=((int)x>>3) + ((int)y<<4) ; if (x == (x & 0xf8)) mask = 0x0f; //f8 else mask = 0xf0; screen[i] = (screen[i] & mask) | (smallbitmap[c][0] & ~mask); screen[i+16] = (screen[i+16] & mask) | (smallbitmap[c][1] & ~mask); screen[i+32] = (screen[i+32] & mask) | (smallbitmap[c][2] & ~mask); screen[i+48] = (screen[i+48] & mask) | (smallbitmap[c][3] & ~mask); screen[i+64] = (screen[i+64] & mask) | (smallbitmap[c][4] & ~mask); end //================================== // put a string of small characters on the screen // x-cood must be on divisible by 4 void video_putsmalls(char x, char y, char *str) begin char i ; for (i=0; str[i]!=0; i++) begin if (str[i]>=0x30 && str[i]<=0x3a) video_smallchar(x,y,str[i]-0x30); else if (str[i]>=0x41) video_smallchar(x,y,str[i]-0x40+12); else if (str[i]==0x20) video_smallchar(x,y,12); else if (str[i]==0x2e) video_smallchar(x,y,10); else if (str[i]==0x2d) video_smallchar(x,y,11); x = x+4; end end //================================== //plot a line //at x1,y1 to x2,y2 with color 1=white 0=black 2=invert //NOTE: this function requires signed chars //Code is from David Rodgers, //"Procedural Elements of Computer Graphics",1985 void video_line(char x1, char y1, char x2, char y2, char c) begin int e; signed char dx,dy,j, temp; signed char s1,s2, xchange; signed char x,y; x = x1; y = y1; dx = cabs(x2-x1); dy = cabs(y2-y1); s1 = csign(x2-x1); s2 = csign(y2-y1); xchange = 0; if (dy>dx) begin temp = dx; dx = dy; dy = temp; xchange = 1; end e = ((int)dy<<1) - dx; for (j=0; j<=dx; j++) begin video_pt(x,y,c) ; if (e>=0) begin if (xchange==1) x = x + s1; else y = y + s2; e = e - ((int)dx<<1); end if (xchange==1) y = y + s2; else x = x + s1; e = e + ((int)dy<<1); end end //================================== //return the value of one point //at x,y with color 1=white 0=black 2=invert char video_set(char x, char y) begin //The following construction //detects exactly one bit at the x,y location i=((int)x>>3) + ((int)y<<4) ; return ( screen[i] & 1<<(7-(x & 0x7))); end //================================== // set up the ports and timers void main(void) begin //init timer 1 to generate sync OCR1A = lineTime; //One NTSC line TCCR1B = 9; //full speed; clear-on-match TCCR1A = 0x00; //turn off pwm and oc lines TIMSK = 0x10; //enable interrupt T1 cmp //init ports DDRD = 0xf0; //video out and int0 input on d.2 //D.5 is sync:1000 ohm + diode to 75 ohm resistor //D.6 is video:330 ohm + diode to 75 ohm resistor // port B is switches with pullups ON DDRB = 0x00; PORTB = 0xff; //port C is DAC output DDRC = 0xff; PORTC = 0; //init A/D converter to //channel 0 ; internal AVcc reference ; left adjust ADMUX = 0b01100001 ; //ON--bit7 and start conversion--bit6 //clock of 500 Khz (xtal/32) bits2-0 ADCSR = 0b11000101 ; //initial trigger level trigLevel = 128; //init index to indicate ready to get data ii = 129 ; //trigger mode 0=level 1=edge trigmode = 0; //initialize synch constants LineCount = 1; syncON = 0b00000000; syncOFF = 0b00100000; //init UART and set baud to 9600 UCSRB = 0x18; UBRRL = 103; putsf("NuS version 1.0\n\r"); //Print NUS video_puts(3,3,cu1); //Print "ECE476" //video_puts(65,3,cu2); //time and voltage scales //video_putsmalls(60,5,tind); sprintf(vs,"%4.0f",(float)120*0.063625*(float)(1<>vscale) ; if (vpoint>78) vpoint=78; if (vpoint<12) vpoint=12; video_pt(k,ADold[k],0); video_pt(k,vpoint,1); ADold[k] = vpoint ; end //freerun mode -- just wait for next trigger if(oneShotenable==0) ii=129; //clear armed state in stop mode else video_putsmalls(4,83,tstop); end //execute the repeat buttons bstep++ ; //These buttons are not in the state machine //because they should autorep at bstep speed if (bstep==4) begin bstep=0; //set the trigger level if (currentSet==4) begin if (PINB.7==0 && trigLevel<255) trigLevel++ ; if (PINB.6==0 && trigLevel>0) trigLevel-- ; sprintf(vs,"%03d",trigLevel); video_putsmalls(108,83,vs); end //set the pulse amplitude level if (currentSet==5) begin if (PINB.7==0 && PulseAmp<255) PulseAmp++ ; if (PINB.6==0 && PulseAmp>0) PulseAmp-- ; sprintf(vs,"%4.1f",(float)PulseAmp*5.00/256.); video_putsmalls(100,5,vs); end //set the pulse duration if (currentSet==6) begin if (PINB.7==0 && PulseDuration<=320) PulseDuration++ ; if (PINB.7==0 && PulseDuration>320 && PulseDuration<=3200) PulseDuration=PulseDuration+10 ; if (PINB.7==0 && PulseDuration>3200 ) PulseDuration=PulseDuration+100 ; if (PINB.6==0 && PulseDuration<=320) PulseDuration-- ; if (PINB.6==0 && PulseDuration>320 && PulseDuration<=3200) PulseDuration=PulseDuration-10 ; if (PINB.6==0 && PulseDuration>3200 ) PulseDuration=PulseDuration-100 ; sprintf(vs,"%4.1f",(float)PulseDuration*0.063625); video_putsmalls(44,5,vs); end //set the pulse spacing if (currentSet==7) begin if (PINB.7==0 && PulseSpacing<=320) PulseSpacing++ ; if (PINB.7==0 && PulseSpacing>320 && PulseSpacing<=3200) PulseSpacing=PulseSpacing+10 ; if (PINB.7==0 && PulseSpacing>3200 ) PulseSpacing=PulseSpacing+100 ; if (PINB.6==0 && PulseSpacing<=320) PulseSpacing-- ; if (PINB.6==0 && PulseSpacing>320 && PulseSpacing<=3200) PulseSpacing=PulseSpacing-10 ; if (PINB.6==0 && PulseSpacing>3200 ) PulseSpacing=PulseSpacing-100 ; sprintf(vs,"%4.1f",(float)PulseSpacing*0.063625); video_putsmalls(72,5,vs); end if (currentSet==2 && oneShotenable) begin if (PINB.7==0 && curx<127) begin video_pt(curx,vzero+2-(ADout[curx]>>vscale),0); curx++ ; video_pt(curx,vzero+2-(ADout[curx]>>vscale),1); end if (PINB.6==0 && curx>0) begin video_pt(curx,vzero+2-(ADout[curx]>>vscale),0); curx-- ; video_pt(curx,vzero+2-(ADout[curx]>>vscale),1); end sprintf(vs,"%5.1f",(float)curx*0.063625*(float)tscaleV[tscale]); video_putsmalls(16,83,vs); if (vselect==0 || vselect==2) sprintf(vs,"%5.2f",(float)ADout[curx]*.0195-2.50); if (vselect==1 || vselect==3) sprintf(vs,"%5.2f",(float)ADout[curx]*.01-1.28); video_putsmalls(40,83,vs); end end //auto rept section //button state machine switch (bstate) begin case 0: //unpressed if (PINB==0xff) break; else begin bstate=1; buttons=PINB; end break; case 1: //posible press if (buttons==PINB) //then actual press begin bstate=2; //set display time if(currentSet==0) begin // #asm("cli") if (PINB.6 && tscale<7) tscale++ ; if (PINB.7 && tscale>0) tscale-- ; sprintf(vs,"%4.0f",tscalefull[tscale] ); //8.144*(float)tscaleV[tscale] video_putsmalls(16,83,vs); // #asm("sei") end //set trigger mode //chose edge/level trigger if (currentSet==3) begin // #asm("cli") if (PINB.7==0 && trigmode<2) trigmode++ ; if (PINB.6==0 && trigmode>0) trigmode-- ; if (trigmode==0) video_putsmalls(64,83,tlevel); if (trigmode==2) video_putsmalls(64,83,text); if (trigmode==1) video_putsmalls(64,83,tfree); // #asm("sei") end //choose run/stop if (PINB.2==0) begin oneShotenable=!oneShotenable ; if (oneShotenable) video_putsmalls(4,83,tstop); else begin video_putsmalls(4,83,trun); video_putsmalls(16,83,blanks); //wipes t/v readout sprintf(vs,"%4.0f",tscalefull[tscale] ); //8.144*(float)tscaleV[tscale] video_putsmalls(16,83,vs); end end // and ARM if in stop mode if (PINB.3==0 && oneShotenable) begin ii=129 ; video_putsmalls(4,83,tarm); end //choose voltage scale--one of 4 level if (currentSet==1) begin if (PINB.7==0 && vselect<3) vselect++ ; if (PINB.6==0 && vselect>0) vselect-- ; if (vselect==0) begin vscale=2; vzero=76; ADMUX = 0b01100001 ; sprintf(vs,"%4.2f",5.00); video_putsmalls(40,83,vs); end if (vselect==1) begin vscale=2; vzero=76; ADMUX = 0b11100001 ; sprintf(vs,"%4.2f",2.56); video_putsmalls(40,83,vs); end if (vselect==2) begin vscale=0; vzero=-80; ADMUX = 0b01100001 ; sprintf(vs,"%4.2f",1.25); video_putsmalls(40,83,vs); end if (vselect==3) begin vscale=0; vzero=-80; ADMUX = 0b11100001 ; sprintf(vs,"%4.2f",0.75); video_putsmalls(40,83,vs); end end //choose stim pulse mode if (PINB.0==0) begin PulseMode++ ; if (PulseMode>3) PulseMode=0 ; if (PulseMode==0) video_putsmalls(24,5,soff); if (PulseMode==1) begin video_putsmalls(24,5,sone); PulseCount=1; //Don't trigger scope SinglePulse=0; //waitfor actual trigger end if (PulseMode==2) begin video_putsmalls(24,5,srept); PulseCount=-1; //trigger scope SinglePulse=1; end if (PulseMode==3) begin video_putsmalls(24,5,stwo); PulseCount=1; SinglePulse=0; //wait for actual trigger end end //stim pulse trigger if (PINB.1==0 && PulseMode==1) begin PulseCount=-1; //trigger scope SinglePulse=1; end if (PINB.1==0 && PulseMode==3) begin PulseCount=-1; SinglePulse=2; end //inc/dec the current parameter to set if (PINB.4==0) begin if (currentSet>0) currentSet-- ; video_putsmalls(112,73,param[currentSet]); end if (PINB.5==0) begin if (currentSet<7) currentSet++ ; video_putsmalls(112,73,param[currentSet]); end end //the actual button press else bstate=0; break; case 2: //possible release if (buttons==PINB) break; else bstate=3; break; case 3: //release if (buttons==PINB) begin bstate=3; break; end else bstate=0; end end //line 211 end //while end //main