' ********************************************************************** ' ** Program : gmbdae.bas - Version : 1.2 ** ' ** Compiler : BASCOM 8051 DEMO, (IDE and LIB V.2.0.11.0) ** ' ** Board : GMB HR168 with GMM ACZero ** ' ** Corporate: grifo(r) ITALIAN TECHNOLOGY ** ' ** Via Dell' Artigiano 8/6 40016 San Giorgio di Piano (BO) ** ' ** Tel.+39 051 892 052 Fax +39 051 893 661 ** ' ** http://www.grifo.com http://www.grifo.it ** ' ** sales@grifo.it tech@grifo.it grifo@grifo.it ** ' ** ** ' ** Written by: Graziano Gaiba 02.02.2005 ** ' ********************************************************************** ' ' This demo uses section 0 of Mini Module PCA to generate, on CN7, a PWM signal ' with preset frequency and duty cycle programmable in percent by console. ' Such signal, connected to an opportune intergrating circuit (RC network, ' operational amplifire with capacitor on feedback, etc.) allows to obtain an ' anlog signal like the one of a D/A. Demo execution depends on which Mini ' Module is used and serial line configuration. ' ' ' Rel. 1.1 03.03.04 - By Graziano Gaiba ' ' Rel. 1.2 02.02.05 - By Graziano Gaiba ' ' Modified to work with GMM ACZero ' ' ' !!!!!!!!!!!!!!!!!!!!!!! ATTENTION !!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ' In menu Options/Compiler/Misc set: ' - Byte End(hex) at least A0 ' ' ' The file compiled is smaller than 2048 bytes, so it can be compiled ' with free demo version of BASCOM 8051. ' ' '****************** Compiler directives ************************** ' $regfile = "8951cc03.dat" $romstart = &H0 ' start address of code for FLASH $ramstart = &H0 ' start address of external RAM $ramsize = &H100 ' 256 bytes of external RAM $crystal = 14745600 ' Microcontroller clock $baud = 19200 ' RS-232 baud rate '$large ' 16 bit addressing for jumps ' (Not for demo version) $map ' Generates address map ' ' '****************** Constants declatation *********************** ' Const Cret = 13 ' Carriage return Const Nl = 10 ' New line Const Clrscr = 12 ' Clear screen Const Bell = 7 ' Bell Cr Alias Ccon.6 ' PCA timer control ' ' '****************** Variables declaration ********************** ' ' Generic use Dim S As Byte , C As Byte ' Generico use and SetPwm Dim S1 As String * 1 ' ' '************************** Main program ****************************** ' Main: ' Inizializes demo Disable Interrupts ' Disabiles interrupts Auxr = &H0C ' Selects Eram on external data area Eecon = &H00 ' Disables Eeprom of Micro P3 = &HFF ' Sets port 3 as input Do Print Chr(clrscr); ' Clear screen Print "Demo 1.2 for GMB HR168 ds 110104" Print Print "Is the GMB HR168 in RS 422 or 485 (Y/N)? "; Do S1 = Waitkey S1 = Ucase(s1) Loop Until S1 = "Y" Or S1 = "N" Print S1 If S1 = "Y" Then Print "Pin 6 of CN4 may be used for communication direction." Print "PWM for D/A not available." Do Loop End If ' Management of PCA capture/compare modules as PWM generators Print Print "Demo of PCA as PWM on pin 6 of GMB HR168 CN7" Print Print "Pin 6 of CN7 can generate a PWM signal that can become an analog signal" Print "(D/A) by a simple integrator (RC network, op. amp. with capacitor on" Print "feedback circuit, etc). PWM resolution is 8 bit while frequency can be" Print "set by software." Print "This demo allows to program duty cicle and uses a frequecy=Fclk/(2*6*256)KHz." C = Adcf C.3 = 0 Adcf = C ' P1.3 as I/O Cmod = &H00 ' Clock frequency is ' FPca divide by 6, peripheral enabled to ' work also in Idle Mode, no interrupt Cr = 1 ' Enable PCA Timer/Counter Do Print Do Input "Duty Cycle (0..100 %): " , S Loop Until S >= 0 And S <= 100 S = S * 2.55 Ccapm0 = &H42 ' Enable PWM on module 0 PCA Ccap0h = S ' Activate PWM output Print "Setting performed." Loop Cr = 0 ' Stops PCA Timer/Counter End ' ' '************************ Program end *************************** '