Quantcast
Channel: MEL PICBASIC Forum
Viewing all articles
Browse latest Browse all 4746

Working with memory

$
0
0
I'm trying to get more familiar with reading and writing to the memory of a 12F683 @4Mhz using PBP3 and simulating it on Proteus's serial out display.

What I want to know is how to write a large number, word sized, to memory, byte size, and then reassmble it. Like this

Code:


clear
trisio =%001101
gpio = 0
include "modedefs.bas"

#config
      __CONFIG _INTOSCIO & _WDTE_ON & _CP_OFF & _MCLRE_OFF & _BOREN_ON & _IESO_OFF & _PWRTE_OFF  & _CPD_OFF &  _FCMEN_OFF       
#endconfig

define OSC 8
osccon = %01111110 'sets 8 MHz oscillator

ansel = %00100101  '
cmcon0 = 7        ' Turn off comparatos     

memory_output1 var byte    ' memory variables
memory_output2 var byte
memory_output3 var byte
memory_output4 var word
memory_output5 var byte
memory_output6 var word
memory_output7 var word

Main:
write 0,5  'playing with memory
write 1,20
write 2,20
read 0, memory_output1
read 1, memory_output2
reaD 2, memory_output3
memory_output4 =  memory_output3 * memory_output2 * memory_output1 * memory_output1

write 3, memory_output4.byte0
write 4, memory_output4.byte1

read 3, memory_output4.byte0
read 4, memory_output4.byte1

memory_output6 = memory_output4.byte0 & memory_output4.byte1 | memory_output7

serout2 gpio.1,84,[10,13,dec memory_output3," ",dec memory_output2," ",dec memory_output6,10,13]
serout2 gpio.1,84,[10,13,dec memory_output7,10,13]
serout2 gpio.1,84,[10,13,"----------------------------------------------",10,13]

goto main

Memory 4 value is 10,000. What I'm trying to do is write memory 4 byte 0 value to memory location 3 and byte1 value to memory location 4. Then I want to read those bytes and assemble them into a word and display it.

I cut and pasted this code from the full program so it may be awkward in places. Your insights would be greatly appreciated.

Viewing all articles
Browse latest Browse all 4746

Trending Articles