Purpose: Using the embedded controller’s internal eeprom as a buffer to input data held long term long term storage (I2C external memory).
Objective: This workshop is designed to familiarize the student with elements of the embedded microcontroller.
Real world application: Memory buffer.
Requirements:
Hardware: Microchip I2C External Memory Chip (24C04), Digital to Analog Converter Chip (AD55), Oscilloscope
Software commands: symbol dev = %01010000, Call AD1, i2cout dev,b2,(b3), i2cin dev,b1,b3
Procedure: Create a program that will generate a sine wave from data stored in the lower half of internal eeprom. When logic 0 is placed on pa3 the program will output the sine function to D to A converter and be displayed on the O-scope.
When logic 1 is placed on pa3 the program will fill I2C external memory with data. The data must be 32 bytes long and will create a function of your choice. After filling long term storage your program will then write the data to the top half of eeprom (the buffer) and then output the data from the buffer to the D to A converter, to be display on the O-scope.
Circuit Drawing for Workshop #10
PicBasic Code for Workshop #10
'$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
'This program inputs data into long term memory (I2C). It then
'writes the data to a buffer (top half of internal eeprom).
'The buffer is then read from and the data is displayed in
'the form of a function seen on an O-scope.
'Herb Wagner
'$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
dirs = %11111111
'set all pins as outputs
'Fill eeprom with sine wave data points
eeprom 0,(254,252,244,233,217,198,176,152,127)
eeprom (102,78,56,37,21,10,2,0,2,10,21,37,56)
eeprom (78,102,127,152,176,198,217,233,244,252)
symbol dev = %01010000
'identify I2C as the
'memory device to
'be used
begn:
call clr_pa3
'clear pa3
call tst_pa3
'test pa3
if bit0 = 0 then sine
'if zero then display sine
'wave function
goto create
'create a function
'/////////////////////////////////////////////////////////////////
'The following code will display a sine wave function 1000 times.
'It will read the data stored in the lower half eeprom.
sine:
for w10 = 1 to 1000
for b1 = 0 to 31
read b1,b2
pins = b2
next b1
next w10
goto begn
'/////////////////////////////////////////////////////////////////
'This block of code will create data (function) that will be
'stored in I2C for long term storage. It is then written into
'the lower half of internal eeprom (the buffer), and then displayed
'a 1000 times.
create:
b1 = 0
for b2 = 32 to 56
'counter to write data into I2C
b3 = b1 * 6 'create data
i2cout dev,b2,(b3) 'write to I2C
pause 10
'required time delay
b1 = b1 + 1
'increm. data variable
next b2
for b2 = 56 to 61 'counter to write
data into I2C
b3 = b3 - 30
'create data
i2cout dev,b2,(b3) 'write to I2C
pause 10
'required time delay
next b2
'The following reads I2C and writes it into top half of internal
'eeprom, which acts as a buffer for the Picstic
for b1 = 32 to 61
i2cin dev,b1,b3
write b1,b3
next b1
'The following displays the data (function) which is now stored
'in the buffer. The function will be outputted a 1000 times.
for w10 = 1 to 1000
for b1 = 32 to 61
read b1,b3
pins = b3
next b1
next w10
goto begn
'/////////////////////////////////////////////////////////////////
'The following is the assembly subroutines required to use pa3
'as an input to direct which function to be displayed.
asm
_tst_pa3
bsf status,5
bsf trisa,3
bcf status,5
bcf _b0,0
btfsc porta,3
bsf _b0,0
goto done
_clr_pa3
bcf porta,3
bsf status,5
bcf trisa,3
bcf status,5
goto done
endasm
end