Skip to main content

DAC

Syntax


DACsetup()

DACout(expression)

Description


Control of the DAC is done by writing directly to the registers.  Details can be found in the User manual of the appropriate part, links in the Hardware Section .

Rather than having built in functions in BASIC, this will be done by subroutines .  Samples of those subroutines are below

Example

On the SuperPRO:

#define
PCB_PINSEL1 *(&H4002C004)
#define PCB_PINMODE1
*(&H4002C044)

#define
DACR *(&H4008C000)
' or use
#include <LPC17xx.bas>

sub
DACsetup
PCB_PINSEL1 =
PCB_PINSEL1 and (not (3<<20)) or (2<<20) ' enable DAC
output
PCB_PINMODE1 = PCB_PINMODE1 or
(2<<20)
' disable pull-ups

endsub

sub DACout(value)
DACR =
value << 6

endsub

main:

DACsetup

for i= 0 to 1023

DACout(i)

wait(10)

next i

On the ARMweb or DINkit:

#define PCB_PINSEL1 *(&HE002C004)

#define
DACR *(&HE006C000)
' or use
#include <LPC21xx.bas>

sub
DACsetup
PCB_PINSEL1 =
PCB_PINSEL1 and (not (3<<18)) or (2<<18) ' enable DAC
output

endsub

sub DACout(value)
DACR =
value << 6

endsub

main:

DACsetup

for i=

0
to

1023
DACout(i)

wait(10)

next
i

\

Differences from other BASICs

\

  • no equivalent in Visual BASIC
  • no equivalent in PBASIC

See also

\