'******************************************************************* ' Program Name : pressure_disp ' Start Date 4th.Apr.2010 ' Author Yoshio KATO ' Description : Used MCU ATtiny2313 low voltage version ' : System Clock 8MHz Internal OSC ' : Receive data from pressure measureing uint by serial com ' : Used 7 segments LED display '******************************************************************* $regfile = "attiny2313.dat" $crystal = 8000000 $baud = 38400 Dim Digit As Byte Dim Wk As Byte Dim I As Byte Dim Temp As Byte Dim Index As Byte Dim Segdata(13) As Byte Dim Rec_data(9) As Byte 'receive data Dim Digit_data(9) As Byte ' Digit control data Config Portb = &HFF Config Portd = &HFE Enable Urxc On Urxc Rec_dt Enable Interrupts Main: Stop Ac ' Analog comparater power off '7segment data Segdata(1) = &HC0 ' 0 a,b,c,d,e,f Segdata(2) = &HF9 ' 1 b,c Segdata(3) = &HA4 ' 2 a,b,d,e,g Segdata(4) = &HB0 ' 3 a,b,c,d,g Segdata(5) = &H99 ' 4 b,c,f,g Segdata(6) = &H92 ' 5 a,c,d,f,g Segdata(7) = &H82 ' 6 a,c,d,e,f,g Segdata(8) = &HD8 ' 7 a,b,c,f Segdata(9) = &H80 ' 8 a,b,c,d,e,f,g Segdata(10) = &H90 ' 9 a,b,c,d,f,g Segdata(11) = &HBF 'minus g-segment only Segdata(12) = &HFF 'blandk Digit_data(1) = &HE0 'digit1 control data Digit_data(2) = &HE4 'digit2 control data Digit_data(3) = &HE8 'digit3 control data Digit_data(4) = &HEC 'digit4 control data Digit_data(5) = &HF0 'digit5 control data Digit_data(6) = &HF4 'digit6 control data Digit_data(7) = &HF8 'digit7 control data Digit_data(8) = &HDC 'digit8 control data Digit_data(9) = &HBC 'digit9 control data Do For I = 1 To 9 Digit = I Wk = Rec_data(i) Select Case Digit 'zero suppression Case 3 : If Wk <> 0 Then 'temperature 10 degree Gosub Dispdata End If Case 4 : If Rec_data(3) = 0 And Wk = &H0A Then Digit = 3 End If Gosub Dispdata Case 9 : If Wk <> 0 Then Gosub Dispdata End If Case Else : Gosub Dispdata End Select Next I Loop End '******************************************************************* ' Display data, using 7 segments LED ' PORTB is data out, PORTD is digit select '******************************************************************* Dispdata: Portb = &HFF 'all segments off Portd = &HFF 'Vcc off Waitus 120 Portb = Segdata(wk + 1) Wk = Digit_data(digit) 'get digit control data Portd = Wk Waitms 2 Return '******************************************************************* ' Serial communication interrupt ' upper 4bit are digit select data ' lower 4bit are value of display '******************************************************************* Rec_dt: Temp = Udr 'get data from UART Index = Temp And &HF0 'upper 4bit are data of digit select Shift Index , Right , 4 'shift right 4 bit Rec_data(index) = Temp And &HF 'lower 4bit are value of display Return