' ********************************************************************** ' ** Program : gmbdae.bas - Version : 1.1 - 24 June 2003 ** ' ** Compiler : BASCOM 8051 DEMO, (IDE and LIB V.2.0.11.0) ** ' ** Board : GMB HR84 with CAN GMx or GMM yyyy ** ' ** 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 ** ' ********************************************************************** ' ' This demo uses section 0 of Mini Module PCA to generate, on CN4, 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. ' ' 28.04.03 - Rel 1.1 By Graziano Gaiba ' ' ' 12.05.03 - Rel 1.2 By Graziano Gaiba ' Added description message about pin 6 of CN4. ' Limited driving code for that signal. ' ' The file compiled is smaller than 2048 bytes, so it can be compiled ' with free demo version of BASCOM 8051. ' '****************** Compiler directives ************************** ' ' Set to 80h internal memory limit by: ' Options/Compiler/Misc $regfile = "grifo_mm.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 Const R = 1 ' Read I2C Bus Const W = 0 ' Write I2C Bus ' Board where the demo is running Const Can_gm1 = "1" Const Can_gm2 = "2" Const Gmm_5115 = "3" Cr Alias Ccon.6 ' PCA timer control ' '****************** Variables declaration ********************** ' ' Board where the demo is running' Dim Board As Byte ' 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.1 for GMB HR84 ds 100203" Print Print "Which Mini Modulo grifo(r) is the demo running on:" Print "1) CAN GM1" Print "2) CAN GM2" Print "3) GMM 5115" Print Print "SELECT: "; Do Board = Inkey() ' Stand by a key Loop Until Board <> 0 Print Chr(board) If Board <> Can_gm1 Then Print "Is the GMB HR84 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 is used for communication direction." Print "PWM for D/A not available." Do Loop End If End If ' Management of PCA capture/compare modules as PWM generators Print Chr(clrscr); ' Clear screen Print "Demo of PCA as PWM on pin 6 of GMB HR84 CN4" Print Print "Pin 6 of CN4 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 *************************** '