Anda di halaman 1dari 29

CONFIG ADC Top 

Previous  Next

Action

Configures the A/D converter.

Syntax

CONFIG ADC = single, PRESCALER = AUTO, REFERENCE = opt

Remarks

ADC Running mode. May be SINGLE or FREE.


PRESCALER A numeric constant for the clock divider. Use AUTO to let the compiler
generate the best value depending on the XTAL
REFERENCE The options depend on the used micro. Some chips like the M163 have
additional reference options. In the definition files you will find :
ADC_REFMODEL = x

This specifies which reference options are available. The possible values are
listed in the table below.

Chip Modes ADC_REFMODEL


2233,4433,4434,8535,m103,m603, OFF 0
m128103
AVCC
m165, m169, m325,m3250, m645,   OFF 1
m6450, m329,m3290, m649,
m6490,m48,m88,m168 AVCC

INTERNAL or INTERNAL_1.1
tiny15,tiny26 AVCC 2

OFF
INTERNAL

INTERNALEXTCAP
tiny13 AVCC 3
INTERNAL
tiny24,tiny44,tiny85 AVCC 4

EXTERNAL or OFF

INTERNAL or INTERNAL_1.1
m164,m324,m644,m640,m1280, AREF or OFF 5
m1281,m2561,m2560
AVCC

INTERNAL1.1

INTERNAL_2.56
tiny261,tiny461,tiny861, AVCC 7
tiny25,tiny45,tiny85
EXTERNAL or OFF

INTERNAL_1.1

INTERNAL_2.56_NOCAP

INTERNAL_2.56_EXTCAP
CAN128, PWM2_3,USB1287, m128, AREF or OFF 8
m16, m163, m32, m323, m64
AVCC

INTERNAL or INTERNAL_2.56

You may also use VALUE=value

When you use VALUE=value, you may specify any value. The disadvantage is that when you port your code
from one chip to another it will not work.

While the AREF, AVCC, etc. are all converter to the right settings, the value can not be converted.

The AD converter is started automatic when you use the CONFIG ADC command.

You can use STOP ADC and START ADC to disable and enable the power of the AD converter.
 

See also

GETADC

Example

'--------------------------------------------------------------------------
------

'name                     : adc.bas

'copyright                : (c) 1995-2005, MCS Electronics

'purpose                  : demonstration of GETADC() function for 8535 or


M163 micro

'micro                    : Mega163

'suited for demo          : yes

'commercial addon needed  : no

'use in simulator         : possible

' Getadc() will also work for other AVR chips that have an ADC converter

'--------------------------------------------------------------------------
------

$regfile = "m163def.dat"                                    ' we use the


M163

$crystal = 4000000

$hwstack = 32                                               ' default use


32 for the hardware stack

$swstack = 10                                               'default use 10


for the SW stack
$framesize = 40                                             'default use 40
for the frame space

'configure single mode and auto prescaler setting

'The single mode must be used with the GETADC() function

'The prescaler divides the internal clock by 2,4,8,16,32,64 or 128

'Because the ADC needs a clock from 50-200 KHz

'The AUTO feature, will select the highest clockrate possible

Config Adc = Single , Prescaler = Auto

'Now give power to the chip

Start Adc  ' NOT required since it will start automatic

'With STOP ADC, you can remove the power from the chip

'Stop Adc

Dim W As Word , Channel As Byte

Channel = 0

'now read A/D value from channel 0

Do

W = Getadc(channel)

Print "Channel " ; Channel ; " value " ; W

Incr Channel

If Channel > 7 Then Channel = 0

Loop
End

'The new M163 has options for the reference voltage

'For this chip you can use the additional param :

'Config Adc = Single , Prescaler = Auto, Reference = Internal

'The reference param may be :

'OFF      : AREF, internal reference turned off

'AVCC     : AVCC, with external capacitor at AREF pin

'INTERNAL : Internal 2.56 voltage reference with external capacitor ar AREF


pin

'Using the additional param on chip that do not have the internal reference
will have no effect.
GETADC Top  Previous  Next

Action

Retrieves the analog value from the specified channel.

Syntax

var = GETADC(channel [,offset])

Remarks

Var The variable that is assigned with the A/D value. This should be a Word or
other 16 bit variable.
Channel The channel to measure. Might be higher then 7 on some chips. The Mega2560
has 16 channels. So the range is 0-15 on a Mega2560.
Offset An optional numeric variable of constant that specifies gain or mode. This
option has effect on newer AVR micro’s only. The offset will be added by the
channel value and inserted into the ADMUX register. This way you can control
gain.

The GETADC() function only will work on microprocessors that have an A/D converter.

The pins of the A/D converter input can be used for digital I/O too.

But it is important that no I/O switching is done while using the A/D converter.

Make sure you turn on the AD converter with the START ADC statement or by setting the proper bit in the
ADC configuration register.

Some micro’s have more then 7 channels. This is supported as well. The ADCSRB register contains a bit named
MUX5 that must be set when a channel higher then 7 is used. The compiler (lib routine) will handle this
automatic. This is true for new chips like Mega1280, Mega2560 and probably other new chips with 100 pins.
 

An example on how to read singled ended input on a Mega1280:

  W = Getadc(0 , 64)  ' from data sheet :  100000 ADC8

  W = Getadc(1, 64)   ' from data sheet :  100001 ADC9

This will read channel 0 and 1. The offset is 64 in order to use singled ended input.

ADC8 is portK.0

GetADC() returns a word variable since the A/D converter data registers consist of 2 registers. The resolution
depends on the chip.

The variable ADCD can be used to access the data register directly. The compiler will handle access to the byte
registers automatically.

See also

CONFIG ADC

Example

'--------------------------------------------------------------------------
------

'name                     : adc.bas

'copyright                : (c) 1995-2005, MCS Electronics

'purpose                  : demonstration of GETADC() function for 8535 or


M163 micro

'micro                    : Mega163

'suited for demo          : yes

'commercial addon needed  : no

'use in simulator         : possible


' Getadc() will also work for other AVR chips that have an ADC converter

'--------------------------------------------------------------------------
------

$regfile = "m163def.dat"                                    ' we use the


M163

$crystal = 4000000

$hwstack = 32                                               ' default use


32 for the hardware stack

$swstack = 10                                               'default use 10


for the SW stack

$framesize = 40                                             'default use 40


for the frame space

'configure single mode and auto prescaler setting

'The single mode must be used with the GETADC() function

'The prescaler divides the internal clock by 2,4,8,16,32,64 or 128

'Because the ADC needs a clock from 50-200 KHz

'The AUTO feature, will select the highest clockrate possible

Config Adc = Single , Prescaler = Auto

'Now give power to the chip

Start Adc

'With STOP ADC, you can remove the power from the chip

'Stop Adc

Dim W As Word , Channel As Byte


 

Channel = 0

'now read A/D value from channel 0

Do

W = Getadc(channel)

Print "Channel " ; Channel ; " value " ; W

Incr Channel

If Channel > 7 Then Channel = 0

Loop

End

'The new M163 has options for the reference voltage

'For this chip you can use the additional param :

'Config Adc = Single , Prescaler = Auto, Reference = Internal

'The reference param may be :

'OFF      : AREF, internal reference turned off

'AVCC     : AVCC, with external capacitor at AREF pin

'INTERNAL : Internal 2.56 voltage reference with external capacitor ar AREF


pin

'Using the additional param on chip that do not have the internal reference
will have no effect.
START Top  Previous  Next

Action

Start the specified device.

Syntax

START device

Remarks

Device TIMER0, TIMER1, COUNTER0 or COUNTER1, WATCHDOG, AC


(Analog comparator power), ADC(A/D converter power) or DAC(D/A
converter)

You must start a timer/counter in order for an interrupt to occur (when the external gate is disabled).

TIMER0 and COUNTER0 are the same device.

The AC and ADC parameters will switch power to the device and thus enabling it to work.

See also

STOP

Example
'--------------------------------------------------------------------------
------

'name                     : adc.bas

'copyright                : (c) 1995-2005, MCS Electronics

'purpose                  : demonstration of GETADC() function for 8535 or


M163 micro

'micro                    : Mega163

'suited for demo          : yes

'commercial addon needed  : no

'use in simulator         : possible

' Getadc() will also work for other AVR chips that have an ADC converter

'--------------------------------------------------------------------------
------

$regfile = "m163def.dat"                                    ' we use the


M163

$crystal = 4000000

$hwstack = 32                                               ' default use


32 for the hardware stack

$swstack = 10                                               'default use 10


for the SW stack

$framesize = 40                                             'default use 40


for the frame space

'configure single mode and auto prescaler setting

'The single mode must be used with the GETADC() function

'The prescaler divides the internal clock by 2,4,8,16,32,64 or 128

'Because the ADC needs a clock from 50-200 KHz


'The AUTO feature, will select the highest clockrate possible

Config Adc = Single , Prescaler = Auto

'Now give power to the chip

Start Adc

'With STOP ADC, you can remove the power from the chip

'Stop Adc

Dim W As Word , Channel As Byte

Channel = 0

'now read A/D value from channel 0

Do

W = Getadc(channel)

Print "Channel " ; Channel ; " value " ; W

Incr Channel

If Channel > 7 Then Channel = 0

Loop

End

'The new M163 has options for the reference voltage

'For this chip you can use the additional param :

'Config Adc = Single , Prescaler = Auto, Reference = Internal

'The reference param may be :

'OFF      : AREF, internal reference turned off

'AVCC     : AVCC, with external capacitor at AREF pin


'INTERNAL : Internal 2.56 voltage reference with external capacitor ar AREF
pin

'Using the additional param on chip that do not have the internal reference
will have no effect.

$FRAMESIZE Top  Previous  Next

Action

Sets the available space for the frame.

Syntax

$FRAMESIZE = var

Remarks

Var A numeric decimal value.

While you can configure the Frame Size in Options, Compiler, Chip, it is good practice to put the value into
your code. This way you do no need the cfg(configuration) file.

The $FRAMESIZE directive overrides the value from the IDE Options.

It is important that the $FRAMESIZE directive occurs in your main project file. It may not be included in an
$include file as only the main file is parsed for $FRAMESIZE

 
See also

$SWSTACK, $HWSTACK

Example

'--------------------------------------------------------------------------
------

'name                     : adc.bas

'copyright                : (c) 1995-2005, MCS Electronics

'purpose                  : demonstration of GETADC() function for 8535 or


M163 micro

'micro                    : Mega163

'suited for demo          : yes

'commercial addon needed  : no

'use in simulator         : possible

' Getadc() will also work for other AVR chips that have an ADC converter

'--------------------------------------------------------------------------
------

$regfile = "m163def.dat"                                    ' we use the


M163

$crystal = 4000000

$hwstack = 32                                               ' default use


32 for the hardware stack

$swstack = 10                                               'default use 10


for the SW stack

$framesize = 40                                             'default use 40


for the frame space
$HWSTACK Top  Previous  Next

Action

Sets the available space for the Hardware stack.

Syntax

$HWSTACK = var

Remarks

Var A numeric decimal value.

While you can configure the HW Stack in Options, Compiler, Chip, it is good practice to put the value into your
code. This way you do no need the cfg(configuration) file.

The $HWSTACK directive overrides the value from the IDE Options.

It is important that the $HWSTACK directive occurs in your main project file. It may not be included in an
$include file as only the main file is parsed for $HWSTACK.

The Hardware stack is room in RAM that is needed by your program. When you use GOSUB label, the
microprocessor pushes the return address on the hardware stack and will use 2 bytes for that. When you use
RETURN, the HW stack is popped back and the program can continue at the proper address. When you nest
GOSUB, CALL or functions, you will use more stack space. Most statements use HW stack because a machine
language routine is called.

See also
$SWSTACK , $FRAMESIZE

Example

'--------------------------------------------------------------------------
------

'name                     : adc.bas

'copyright                : (c) 1995-2005, MCS Electronics

'purpose                  : demonstration of GETADC() function for 8535 or


M163 micro

'micro                    : Mega163

'suited for demo          : yes

'commercial addon needed  : no

'use in simulator         : possible

' Getadc() will also work for other AVR chips that have an ADC converter

'--------------------------------------------------------------------------
------

$regfile = "m163def.dat"                                    ' we use the


M163

$crystal = 4000000

$hwstack = 32                                               ' default use


32 for the hardware stack

$swstack = 10                                               'default use 10


for the SW stack

$framesize = 40                                             'default use 40


for the frame space
$SWSTACK Top  Previous  Next

Action

Sets the available space for the software stack.

Syntax

$SWSTACK = var

Remarks

Var A numeric decimal value.

While you can configure the SW Stack in Options, Compiler, Chip, it is good practice to put the value into your
code. This way you do no need the cfg(configuration) file.

The $SWSTACK directive overrides the value from the IDE Options.

It is important that the $SWSTACK directive occurs in your main project file. It may not be included in an
$include file as only the main file is parsed for $SWSTACK

See also

$HWSTACK , $FRAMESIZE

 
 

Example

'--------------------------------------------------------------------------
------

'name                     : adc.bas

'copyright                : (c) 1995-2005, MCS Electronics

'purpose                  : demonstration of GETADC() function for 8535 or


M163 micro

'micro                    : Mega163

'suited for demo          : yes

'commercial addon needed  : no

'use in simulator         : possible

' Getadc() will also work for other AVR chips that have an ADC converter

'--------------------------------------------------------------------------
------

$regfile = "m163def.dat"                                    ' we use the


M163

$crystal = 4000000

$hwstack = 32                                               ' default use


32 for the hardware stack

$swstack = 10                                               'default use 10


for the SW stack

$framesize = 40                                             'default use 40


for the frame space
STOP Top  Previous  Next

Action

Stop the specified device. Or stop the program

Syntax

STOP device

STOP

Remarks

Device TIMER0, TIMER1, COUNTER0 or COUNTER1, WATCHDOG, AC


(Analog comparator power) , ADC(A/D converter power) or DAC(D/A
converter)

The single STOP statement will end your program by generating a never ending loop. When END is used it will
have the same effect but in addition it will disable all interrupts.

The STOP statement with one of the above parameters will stop the specified device.

TIMER0 and COUNTER0 are the same device.

The AC and ADC parameters will switch power off the device to disable it and thus save power.

See also

START , END
 

Example

See START example

Assembler mnemonics Top  Previous  Next

BASCOM supports the mnemonics as defined by Atmel.

The Assembler accepts mnemonic instructions from the instruction set.

A summary of the instruction set mnemonics and their parameters is given here. For a detailed description of
the Instruction set, refer to the AVR Data Book.

Mnemonics Operands Description Operation Flags Clock


ARITHMETIC          
AND LOGIC
INSTRUCTIONS
ADD Rd, Rr Add without Carry Rd = Rd + Rr Z,C,N,V,H 1
ADC Rd, Rr Add with Carry Rd = Rd + Rr + C Z,C,N,V,H 1
SUB Rd, Rr Subtract without Carry Rd = Rd – Rr Z,C,N,V,H 1
SUBI Rd, K Subtract Immediate Rd = Rd – K Z,C,N,V,H 1
SBC Rd, Rr Subtract with Carry Rd = Rd - Rr - C Z,C,N,V,H 1
SBCI Rd, K Subtract Immediate with Rd = Rd - K - C Z,C,N,V,H 1
Carry
AND Rd, Rr Logical AND Rd = Rd · Rr Z,N,V 1
ANDI Rd, K Logical AND with Rd = Rd · K Z,N,V 1
Immediate
OR Rd, Rr Logical OR Rd = Rd v Rr Z,N,V 1
ORI Rd, K Logical OR with Rd = Rd v K Z,N,V 1
Immediate
EOR Rd, Rr Exclusive OR Rd = Rd Å Rr Z,N,V 1
COM Rd Ones Complement Rd = $FF - Rd Z,C,N,V 1
NEG Rd Twos Complement Rd = $00 - Rd Z,C,N,V,H 1
SBR Rd,K Set Bit(s) in Register Rd = Rd v K Z,N,V 1
CBR Rd,K Clear Bit(s) in Register
Rd = Rd · ($FFh - Z,N,V 1
K)
INC Rd Increment Rd = Rd + 1 Z,N,V 1
DEC Rd Decrement Rd = Rd - 1 Z,N,V 1
TST Rd Test for Zero or Minus Rd = Rd · Rd Z,N,V 1
CLR Rd Clear Register Rd = Rd Å Rd Z,N,V 1
SER Rd Set Register Rd = $FF None 1
ADIW Rdl, K6 Add Immediate to Word Rdh:Rdl = Rdh:Rdl Z,C,N,V,S 2
+K
 

Adiw r24, K6
SBIW Rdl, K6 Subtract Immediate from Rdh:Rdl = Rdh:Rdl Z,C,N,V,S 2
Word -K
 

Sbiw R24,K6
MUL Rd,Rr Multiply Unsigned R1, R0 = Rd * Rr C 2*
BRANCH          
INSTRUCTIONS
RJMP K Relative Jump PC = PC + k + 1 None 2
IJMP   Indirect Jump to (Z) PC = Z None 2
JMP K Jump PC = k None 3
RCALL K Relative Call Subroutine PC = PC + k + 1 None 3
ICALL   Indirect Call to (Z) PC = Z None 3
CALL K Call Subroutine PC = k None 4
RET   Subroutine Return PC = STACK None 4
RETI   Interrupt Return PC = STACK I 4
CPSE Rd,Rr Compare, Skip if Equal if (Rd = Rr) PC = None 1/2
PC + 2 or 3
CP Rd,Rr Compare Rd - Rr Z,C,N,V,H, 1
CPC Rd,Rr Compare with Carry Rd - Rr - C Z,C,N,V,H 1
CPI Rd,K Compare with Immediate Rd - K Z,C,N,V,H 1
SBRC Rr, b Skip if Bit in Register If (Rr(b)=0) PC = None 1/2
Cleared PC + 2 or 3
SBRS Rr, b Skip if Bit in Register Set If (Rr(b)=1) PC = None 1/2
PC + 2 or 3
SBIC P, b Skip if Bit in I/O Register If(I/O(P,b)=0) PC = None 2/3
Cleared PC + 2 or 3
SBIS P, b Skip if Bit in I/O Register If(I/O(P,b)=1) PC = None 2/3
Set PC + 2 or 3
BRBS s, k Branch if Status Flag Set if (SREG(s) = 1) None 1/2
then PC=PC+k + 1
BRBC s, k Branch if Status Flag if (SREG(s) = 0) None 1/2
Cleared then PC=PC+k + 1
BREQ K Branch if Equal if (Z = 1) then PC = None 1/2
PC + k + 1
BRNE K Branch if Not Equal if (Z = 0) then PC = None 1/2
PC + k + 1
BRCS K Branch if Carry Set if (C = 1) then PC = None 1/2
PC + k + 1
BRCC K Branch if Carry Cleared if (C = 0) then PC = None 1/2
PC + k + 1
BRSH K Branch if Same or Higher if (C = 0) then PC = None 1/2
PC + k + 1
BRLO K Branch if Lower if (C = 1) then PC = None 1/2
PC + k + 1
BRMI K Branch if Minus if (N = 1) then PC = None 1/2
PC + k + 1
BRPL K Branch if Plus if (N = 0) then PC = None 1/2
PC + k + 1
BRGE K Branch if Greater or if (N V= 0) then PC None 1/2
Equal, Signed = PC+ k + 1
BRLT K Branch if Less Than, if (N V= 1) then PC None 1/2
Signed = PC + k + 1
BRHS K Branch if Half Carry Flag if (H = 1) then PC = None 1/2
Set PC + k + 1
BRHC K Branch if Half Carry Flag if (H = 0) then PC = None 1/2
Cleared PC + k + 1
BRTS K Branch if T Flag Set if (T = 1) then PC = None 1/2
PC + k + 1
BRTC K Branch if T Flag Cleared if (T = 0) then PC = None 1/2
PC + k + 1
BRVS K Branch if Overflow Flag if (V = 1) then PC = None 1/2
is Set PC + k + 1
BRVC K Branch if Overflow Flag if (V = 0) then PC = None 1/2
is Cleared PC + k + 1
BRIE K Branch if Interrupt if ( I = 1) then PC = None 1/2
Enabled PC + k + 1
BRID K Branch if Interrupt if ( I = 0) then PC = None 1/2
Disabled PC + k + 1
DATA          
TRANSFER
INSTRUCTIONS
MOV Rd, Rr Copy Register Rd = Rr None 1
LDI Rd, K Load Immediate Rd = K None 1
LDS Rd, k Load Direct Rd = (k) None 2
LD Rd, X Load Indirect Rd = (X) None 2
LD Rd, X+ Load Indirect and Post- Rd = (X), X = X + 1 None 2
Increment
LD Rd, -X Load Indirect and Pre- X = X - 1, Rd =(X) None 2
Decrement
LD Rd, Y Load Indirect Rd = (Y) None 2
LD Rd, Y+ Load Indirect and Post- Rd = (Y), Y = Y + 1 None 2
Increment
LD Rd, -Y Load Indirect and Pre- Y = Y - 1, Rd = (Y) None 2
Decrement
LDD Rd,Y+q Load Indirect with Rd = (Y + q) None 2
Displacement
LD Rd, Z Load Indirect Rd = (Z) None 2
LD Rd, Z+ Load Indirect and Post- Rd = (Z), Z = Z+1 None 2
Increment
LD Rd, -Z Load Indirect and Pre- Z = Z - 1, Rd = (Z) None 2
Decrement
LDD Rd, Z+q Load Indirect with Rd = (Z + q) None 2
Displacement
STS k, Rr Store Direct (k) = Rr None 2
ST X, Rr Store Indirect (X) = Rr None 2
ST X+, Rr Store Indirect and Post- (X) = Rr, X = X + 1 None 2
Increment
ST -X, Rr Store Indirect and Pre- X = X - 1, (X) = Rr None 2
Decrement
ST Y, Rr Store Indirect (Y) = Rr None 2
ST Y+, Rr Store Indirect and Post- (Y) = Rr, Y = Y + 1 None 2
Increment
ST -Y, Rr Store Indirect and Pre- Y = Y - 1, (Y) = Rr None 2
Decrement
STD Y+q,Rr Store Indirect with (Y + q) = Rr None 2
Displacement
ST Z, Rr Store Indirect (Z) = Rr None 2
ST Z+, Rr Store Indirect and Post- (Z) = Rr, Z = Z + 1 None 2
Increment
ST -Z, Rr Store Indirect and Pre- Z = Z - 1, (Z) = Rr None 2
Decrement
STD Z+q,Rr Store Indirect with (Z + q) = Rr None 2
Displacement
LPM   Load Program Memory R0 =(Z) None 3
IN Rd, P In Port Rd = P None 1
OUT P, Rr Out Port P = Rr None 1
PUSH Rr Push Register on Stack STACK = Rr None 2
POP Rd Pop Register from Stack Rd = STACK None 2
BIT AND BIT-          
TEST
INSTRUCTIONS
LSL Rd Logical Shift Left Rd(n+1) Z,C,N,V,H 1
=Rd(n),Rd(0)=
0,C=Rd(7)
LSR Rd Logical Shift Right Rd(n) = Rd(n+1), Z,C,N,V 1
Rd(7) =0, C=Rd(0)
ROL Rd Rotate Left Through Rd(0) =C, Rd(n+1) Z,C,N,V,H 1
Carry =Rd(n),C=Rd(7)
ROR Rd Rotate Right Through Rd(7) =C,Rd(n) Z,C,N,V 1
Carry =Rd(n+1),C¬Rd(0)
ASR Rd Arithmetic Shift Right Rd(n) = Rd(n+1), Z,C,N,V 1
n=0..6
SWAP Rd Swap Nibbles Rd(3..0) « Rd(7..4) None 1
BSET S Flag Set SREG(s) = 1 SREG(s) 1
BCLR S Flag Clear SREG(s) = 0 SREG(s) 1
SBI P, b Set Bit in I/O Register I/O(P, b) = 1 None 2
CBI P, b Clear Bit in I/O Register I/O(P, b) = 0 None 2
BST Rr, b Bit Store from Register to T = Rr(b) T 1
T
BLD Rd, b Bit load from T to Rd(b) = T None 1
Register
SEC   Set Carry C=1 C 1
CLC   Clear Carry C=0 C 1
SEN   Set Negative Flag N=1 N 1
CLN   Clear Negative Flag N=0 N 1
SEZ   Set Zero Flag Z=1 Z 1
CLZ   Clear Zero Flag Z=0 Z 1
SEI   Global Interrupt Enable I = 1 I 1
CLI   Global Interrupt Disable I = 0 I 1
SES   Set Signed Test Flag S=1 S 1
CLS   Clear Signed Test Flag S=0 S 1
SEV   Set Twos Complement V=1 V 1
Overflow
CLV   Clear Twos Complement V = 0 V 1
Overflow
SET   Set T in SREG T=1 T 1
CLT   Clear T in SREG T=0 T 1
SHE   Set Half Carry Flag in H=1 H 1
SREG
CLH   Clear Half Carry Flag in H = 0 H 1
SREG
NOP   No Operation   None 1
SLEEP   Sleep   None 1
WDR   Watchdog Reset   None 1

* ) Not available in base-line microcontrollers

The Assembler is not case sensitive.


The operands have the following forms:

Rd: R0-R31 or R16-R31 (depending on instruction)

Rr: R0-R31

b: Constant (0-7)

s: Constant (0-7)

P: Constant (0-31/63)

K: Constant (0-255)

k: Constant, value range depending on instruction.

q: Constant (0-63)

Rdl:  R24, R26, R28, R30. For ADIW and SBIW instructions

Sample Electronics cable programmer Top  Previous  Next

Sample Electronics submitted the simple cable programmer.

They produce professional programmers too. This simple programmer you can make yourself within 10
minutes.

What you need is a DB25 centronics male connector, a flat cable and a connector that can be connected to the
target MCU board.

The connections to make are as following:

DB25 pin Target MCU Target MCU Target MCU pin 8515 DT104
pin(AT90S8535)
M103/M128
2, D0 MOSI, pin 6 PE.0, 2 MOSI, 6 J5, pin 4
4, D2 RESET, pin 9 RESET, 20 RESET, 9 J5, pin 8
5, D3 CLOCK, pin 8 PB.1,11 CLOCK, 8 J5, pin 6
11, BUSY MISO, pin 7 PE.1, 3 MISO, 7 J5, pin 5
18-25,GND GROUND GROUND GND,20 J5, pin 1

The MCU pin numbers are shown for an 8535! And 8515

Note that 18-25 means pins 18,19,20,21,22,23,24 and 25

You can use a small resistor of 100-220 ohm in series with the D0, D2 and D3 line in order not to short circuit
your LPT port in the event the MCU pins are high.

It was tested without these resistors and no problems occurred.

Tip : when testing programmers etc. on the LPT it is best to buy an I/O card for your PC that has a LPT
port. This way you don’t destroy your LPT port that is on the motherboard in the event you make a mistake!

The following picture shows the connections to make. Both a setup for the DT104 and stand-alone PCB are
shown.
 

I received the following useful information:

I have been having spurious success with the simple cable programmer from Sample Electronics for the AVR
series.

After resorting to hooking up the CRO I have figured it out (I think). When trying to identify the chip, no
response on the MISO pin indicates that the Programming Enable command has not been correctly received by
the target.

The SCK line Mark/Space times were okay but it looked a bit sad with a slow rise time but a rapid fall time. So
I initially tried to improve the rise

time with a pull-up. No change ie still could not identify chip. I was about to add some buffers when I came
across an Atmel app note for their serial programmer "During this first phase of the programming cycle,
keeping the SCK line free from pulses is critical, as pulses will cause the target AVR to loose synchronization
with the programmer. When synchronization is lost, the only means of regaining synchronization is to release
the RESET line for more than 100ms."
 

I have added a 100pF cap from SCK to GND and works first time every time now. The SCK rise time is still sad
but there must have been enough noise to corrupt the initial command despite using a 600mm shielded cable.

ATMEGA163 Top  Previous  Next

This page is intended to show the outline of the chip and to provide additional information that might not be
clear from the data sheet.

The M163 by default uses the internal clock running at 1 MHz

When you have problems with timing set the right fuse bit A987= 0101. This will solve this problem.

 
I have just found a small difference in PortB when using the Mega163 in place of a 8535. The difference is in
regard to PortB.4 - PortB.7 when not used as a SPI

interface. The four upper bits of PortB are shared with the hardware SPI unit.

If the SPI is configured in SLAVE mode (DEFAULT) the MOSI , SCK , /SS

Are configured as inputs, Regardless of the DDRB setting !

The /SS (slave select) pin also has restrictions on it when using it as a general input.- see data sheet ATmega163
- p57.

This sample allows you to use the upper nibble of PortB as outputs.

Portb = &B0000_0000

DDRB = &B1111_0000 'set upper bits for output.

Spcr = &B0001_0000 ' set SPI to Master and Disable.

If The SPCR register is not set for Master, you cannot set the pins for

Output.

Anda mungkin juga menyukai