;************************************************************************************* ;7 Segment and 8 LED Bar Graph with interrupt sample code. Written by Nathan Scherdin ;hacked up by Dale K. ;************************************************************************************* ;This table is used by interrupt handler code. Do Not Edit display bytetable %11111100,%01100000,%11011010,%11110010,%01100110,%10110110,%10111110,%11100000,%11111110,%11100110, | %11101110,%00111110,%10011100,%01111010,%10011110,%10001110 EightLED bytetable %00000000,%10000001,%01000010,%00100100,%00011000,%00100100,%01000010,%10000001,%11111111,%00000000 ;The three variables are used by interrupt handler code. Do Not Edit graph var byte ;each bit sets the bar graph led states seg1 var byte ;each bit sets the segment led states seg2 var byte ;each bit sets the segment led states counter var word Tcount var word Tcount = 0 start gosub inithandler counter=0 ;************************************************************************************** ;SegmentCount is where you would added your code or modify the existing code. ;The variable Tcount handles the 10's and Counter handles the 1's. When counter = 9, ;tcount is incremented giving you the 10 count. The label StartOver handles the display ;after 99 and resets it. Display and EightLED are byte tables. The value in brackets () ;is a pointer and tells the program to go to that position in the bytetable and load ;the value found in that postion. You can also use simple statements like seg2 = %11111100 ;and seg1 = %01100000 this would make the display read 10. Comment out all the code in the ;loop and uncomment the 2 seg commands to see a demonstration. The Display byte table is ;read from left to right. The first %11111100 sets the 7 segment to display 0, the ;%01100000 setting the display to a 1 and so on. ;************************************************************************************** SegmentCount tcount = tcount + 1 If tcount = 10 then StartOver For counter = 0 to 9 seg2=display(counter) seg1=display(tcount) graph=EightLed(tcount) Pause 200 Next ; Seg2=%11111100 ; seg1=%01100000 goto SegmentCount StartOver tcount = 0 Goto SegmentCount ;***DO NOT EDIT CODE BELOW THIS LINE*** dataport var OUTL ;alias graph,seg1 and seg2 data port for interrupt handler muxport var OUTH ;alias multiplexer control pins port for interrupt handler inithandler low p8 ;init mux pins used by interrupt handler low p9 low p13 dirl = 0 ;p0-7 outputs T1CON.bit0 = 1 ;timer1 starts counting PIE1.bit0 = 1 ;unmask timer1 int PEIE = 1 ;enable all unmasked peripheral interrupts GIE = 1 ;enable all unmasked interrupts return ;This is the assembly interrupt handler to run the two 7 seg displays and the 8 led graph isr_mode var byte ;used by interrupt handler israsm{ bcf PIR1,0 ;clear Timer1 interrupt flag clrf DATAPORT&0x1FF ;clear current state of P0-P7 banksel ISR_MODE&0x1FF incf ISR_MODE&0x7F,f ;increment MODE movfw ISR_MODE&0x7F ;put MODE value in work register banksel 0 set_seg1 addlw -1 ;subtract 1 skpz ;if zero point to seg1 and load value into p0-p7 goto set_seg2 ;else check seg2 bsf MUXPORT&0x1FF,0 bcf MUXPORT&0x1FF,1 bcf MUXPORT&0x1FF,7 banksel SEG1&0x1FF movfw SEG1&0x7F banksel 0 movwf DATAPORT&0x1FF goto exitint set_seg2 addlw -1 ;subtract 1 skpz ;if zero point to seg2 and load value into p0-p7 goto set_graph ;else set graph bcf MUXPORT&0x1FF,0 bsf MUXPORT&0x1FF,1 bcf MUXPORT&0x1FF,7 banksel SEG2&0x1FF movfw SEG2&0x7F banksel 0 movwf DATAPORT&0x1FF goto exitint set_graph bcf MUXPORT&0x1FF,0 ;point to graph and load value unto p0-p7 bcf MUXPORT&0x1FF,1 bsf MUXPORT&0x1FF,7 banksel GRAPH&0x1FF movfw GRAPH&0x7F banksel 0 movwf DATAPORT&0x1FF banksel ISR_MODE&0x1FF clrf ISR_MODE&0x7F ;Clear MODE to point to seg1 on next interrupt exitint banksel 0 movlw 0xD5 ;set timer so interrupt executes 180 times a second(refreshes seg1,seg2 and graph 60 times a second each) movwf TMR1H }