' ******************************************************************* ' * Program : PWM8254.BAS Version : 1.1 - 06 Setptember 1999 * ' * Compiler: BASCOM 8051 (IDE V.1.0.0.16, LIB V.1.10) * ' * Firm: Grifo(r) Via Dell'Artigiano 8/6 * ' * 40016 San Giorgio di Piano * ' * Tel. +39-051-892052 Fax +39-051-893661 * ' * http://www.grifo.com http://www.grifo.it * ' * sales@grifo.it tech@grifo.it grifo@grifo.it * ' * * ' * Written by: Graziano Gaiba * ' ******************************************************************* ' ' Program designed to work with BASCOM 8051 and a GPC(r) F2 board ' connected to an EMI 01 board. ' This program drives the two PWM outputs, avaiable on the EMI 01 board, ' capable to generate a tension between -10 and +10 V. ' '************************* Compiler Directives ******************************* ' $romstart = &H8050 ' Start address of machine code $ramstart = &HD000 ' Start address of data area $ramsize = &H2800 ' 10k of data area $crystal = 11059200 ' Clock of microcontroller $baud = 9600 ' RS-232 baud rate $large ' 16 bit addressing mode ' '************************* Variables Declaration ****************************** ' Dim V As Word , S As Single , C As String * 1 ' Variabili di uso generico Dim Nimp As Word ' Numero impulsi per generare Vout Dim Indstat As Word , Indcnt2 As Word ' Indirizzi registri 8253 Dim Cmdw2 As Byte ' Parola di comando per 8253 ' '***************************** Main Program *********************************** ' Waitms 1 ' Delay for signals settling Print Chr(12) ' Clears the screen Print "PLEASE SELECT WHICH IC 8254 TO USE (A or B) " ; C = Waitkey ' Waits for a key Print C ' Prints it If C = "a" Then Goto Selection_a Else Goto Selection_b ' If the key is 'a' Selection_a: ' Use IC 8254 A Indstat = &HFA43 ' Assign address 8254 A status register Indcnt2 = &HFA42 ' Assign address counter 2 A data register Goto Continue ' Countinues Selection_b: ' Use IC 8254 B Indstat = &HFA83 ' Assign address 8254 B status register Indcnt2 = &HFA82 ' Assign address counter 2 B data register Continue: ' REM endif Cmdw2 = &HB2 ' Parola di comando per contatore 2: modo 1 Out Indstat , Cmdw2 ' Inizializzazione contatore 2 Print : Print ' Spacing Print "PROGRAM FOR GENERATING A CONTINUOUS VOLTAGE" Print "SELECTABLE BETWEEN -10V AND +10V, BY A PWM SIGNAL" Repeat: ' Repeat forever Print : Print : Print : ' Spacing Print "PLEASE INSERT A VALUE BETWEEN -10 AND +10" Input S ' Read the requested output ' Voltage value ' Calculates the number of impulses to send 'Nimp = ((s + 10.0) * 204.75) If S = -10.0 Then Nimp = 1 Else S = S + 10.0 S = S * 204.75 Nimp = S End If Print "Number of Impulses = " ; Nimp ' Prints the number of impulses to send V = Low(nimp) ' Low byte of impulses number Print "Low byte of number of impulses = " ; V ' Print it Out Indcnt2 , Low(nimp) ' Print it V = High(nimp) ' High byte of impulses number Print "High byte of number of impulses = " ; V ' Print it Out Indcnt2 , High(nimp) ' Print it Goto Repeat ' Repeat forever End ' '******************************** Program End ******************************** '