CPEEKH

From MCS Wiki AVR
(Difference between revisions)
Jump to: navigation, search
(Created page with "= <span class="f_Header">Action</span> = Returns a byte stored in upper page of code memory of micro with more then 64KB such as M103, M128. <span style="font-family: Arial;...")
 
 
(2 intermediate revisions by one user not shown)
Line 45: Line 45:
 
<span style="font-family: Arial;">&nbsp;</span>
 
<span style="font-family: Arial;">&nbsp;</span>
  
CpeekH(0) will return the first byte of the upper 64KB.
+
The similar Cpeek() function only works on the first 64 KB page. It was intended for processors with memory up to 64 KB.
  
Since the M103 has 64K words of code space the LPM instruction can not access the 64 upper Kbytes.
+
When processors were made by Atmel with larger memory like the Mega128 (128 KB) the cpeekH() function was added.
  
The CpeekH() function peeks in the upper 64 KB.
+
The CpeekH() function uses the ELPM instruction instead of the LPM instruction that Cpeek() uses.
  
This function should be used with the M103 or M128 only.
+
&nbsp;
 +
 
 +
Since the memory is broken up in page of 64 KB, the cpeekH() function also access the memory in pages.
 +
 
 +
You can also omit the page number in which case the compiler will calculate the proper page address.
 +
 
 +
&nbsp;
  
 
CpeekH(address,0) will work on the first page (first 64 KB)
 
CpeekH(address,0) will work on the first page (first 64 KB)
  
CpeekH(addres,1) will work on the second page (second 64 KB)
+
CpeekH(address,1) will work on the second page (second 64 KB)
  
<span style="font-family: Arial;">&nbsp;</span>
+
&nbsp;
 +
 
 +
[[File:Notice.jpg]]When omitting the page, the compiler will calculate and load the page register automatically.
  
 
<span style="font-family: Arial;">&nbsp;</span>
 
<span style="font-family: Arial;">&nbsp;</span>
 +
 +
&nbsp;While the AVR uses word addresses since all instructions are 2 bytes long, the Cpeek() function uses a byte address. You need to take that in consideration with for example a boot loader address. The Atmel data sheet will only mention word addresses. For example boot loader address $1000 in the data sheet is $2000 and $2001 byte address for Cpeek().
  
 
= <span class="f_Header">See also</span> =
 
= <span class="f_Header">See also</span> =

Latest revision as of 22:25, 13 December 2014

Contents

Action

Returns a byte stored in upper page of code memory of micro with more then 64KB such as M103, M128.

 

 

Syntax

var = CPEEKH( address [,page] )

 

 

Remarks

Var

Numeric variable that is assigned with the content of the program memory at

address

address

Numeric variable or constant with the address location

page

A numeric variable or constant with the page address. Each page is 64 KB.

 

The similar Cpeek() function only works on the first 64 KB page. It was intended for processors with memory up to 64 KB.

When processors were made by Atmel with larger memory like the Mega128 (128 KB) the cpeekH() function was added.

The CpeekH() function uses the ELPM instruction instead of the LPM instruction that Cpeek() uses.

 

Since the memory is broken up in page of 64 KB, the cpeekH() function also access the memory in pages.

You can also omit the page number in which case the compiler will calculate the proper page address.

 

CpeekH(address,0) will work on the first page (first 64 KB)

CpeekH(address,1) will work on the second page (second 64 KB)

 

Notice.jpgWhen omitting the page, the compiler will calculate and load the page register automatically.

 

 While the AVR uses word addresses since all instructions are 2 bytes long, the Cpeek() function uses a byte address. You need to take that in consideration with for example a boot loader address. The Atmel data sheet will only mention word addresses. For example boot loader address $1000 in the data sheet is $2000 and $2001 byte address for Cpeek().

See also

PEEK , POKE , INP , OUT

 

 

Example


'-----------------------------------------------------------------------------------------
'name : peek.bas
'copyright : (c) 1995-2005, MCS Electronics
'purpose : demonstrates PEEk, POKE, CPEEK, INP and OUT
'micro : Mega48
'suited for demo : yes
'commercial addon needed : no
'-----------------------------------------------------------------------------------------
 
$regfile = "m48def.dat" ' specify the used micro
$crystal = 4000000 ' used crystal frequency
$baud = 19200 ' use baud rate
$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
 
Dim I As Integer , B1 As Byte
'dump internal memory
For I = 0 To 31 'only 32 registers in AVR
B1 = Peek(i) 'get byte from internal memory
Print Hex(b1) ; " ";
'Poke I , 1 'write a value into memory
Next
Print 'new line
'be careful when writing into internal memory !!
 
'now dump a part ofthe code-memory(program)
For I = 0 To 255
B1 = Cpeek(i) 'get byte from internal memory
Print Hex(b1) ; " ";
Next
'note that you can not write into codememory!!
 
Out &H8000 , 1 'write 1 into XRAM at address 8000
B1 = Inp(&H8000) 'return value from XRAM
Print B1
End

Languages   English Deutsch  
Personal tools
Namespaces
Variants
Actions
Navigation
In other languages
Language