This is the program which i wrote to communicate with CMUcam. I faced some prblem regarding storing data to EEprom. The problem that i faced was the Pic took a long time to store the data to the Eeprom. It take about 5s to store about 800 bytes. I suspect delay happened when i store data to the array which is created then only store into the Eeprom. I used this way to ensure no data is lost during transfer using USArt. Did my program got problem or not which cause the Pic to so slow?
DEFINE OSC 20 ' 20MHz crystal
DEFINE HSER_RCSTA 90h ' enable serial port
DEFINE HSER_TXSTA 24h ' enable transmit register
DEFINE HSER_BAUD 115200 ' 19200 baud rate
DEFINE HSER_SPBRG 64 ' 19200 baud rate
DEFINE HSER_CLROERR 1 ' automatically close
DEFINE I2C_SLOW 1 ' standard
DEFINE LOADER_USED 1
'************************************************* *******************
'Declaration of I/O pins and Variables
'************************************************* *******************
w VAR WORD
a VAR WORD
b VAR WORD
c VAR BYTE
counter VAR BYTE
char VAR BYTE ' Storage for serial character
char2 VAR BYTE ' Storage for serial character
add VAR BYTE
value VAR BYTE[96]
'value2 VAR BYTE[80]
SCL VAR PORTC.3 ' Clock pin
SDA VAR PORTC.4 ' Data pin
CONT VAR BYTE
col VAR BYTE
row VAR BYTE
B0 VAR WORD ' Address
B1 VAR BYTE ' Data 1
B2 VAR BYTE ' Data 2
B3 VAR BYTE
'************************************************* *******************
'Clearing all register
'************************************************* *******************
Clear ' clear all register
'************************************************* *******************
a = 0 ' Starting address for Eeprom
col = 30
row = 19 '
CONT = $A0
'************************************************* *******************
High PORTB.0
Pause 1000 ' Wait for LCD to startup
Low PORTB.0
LCDOut $fe, 1 ' Clear LCD screen
High PORTB.0
LCDOut "start" ' Display Hello
Pause 1000 ' Wait 3 second
Low PORTB.0
Pause 1000
High PORTB.0
LCDOut $fe, 1 ' Clear LCD screen
LCDOut "CMU"
Pause 1000 ' Wait 2 second
Low PORTB.0
'************************************************* *******************
loop: HSerin 1, reset, [char] ' Get a char from serial port
Pause 2000
LCDOut $fe, 1 ' Clear LCD screen
LCDOut char ' Send char to display
High PORTB.0
Pause 1000
Low PORTB.0
IF Char = "A" Then pm
reset: HSerout ["rs",13] ' reset CMUcam
High PORTB.1
Pause 1000
Low PORTB.1
GoTo loop
pm: HSerout ["pm 1",13]
Pause 1000
HSerin [char2]
IF char2 ="A" Then
GoTo set
Else
GoTo pm
EndIF
set: Low PORTE.0
High PORTA.5
HSerout ["CR 17 10 18 32 ",13] ' set CMU to YCrCb mode and 4 fps
Pause 1000
Low PORTA.5
GoSub check ' goto check ACK signal
setw: High PORTA.5
HSerout ["SW 11 ", DEC row," 30 ", DEC row,13]
Pause 500
Low PORTB.5
GoTo dump
check: HSerin 1, out, [char2]
LCDOut $fe, 1 ' Clear LCD screen
LCDOut char2 ' Send char to display
Pause 1000
out: IF char2="A" Then
GoTo setw
Else
GoTo set
EndIF
Return
dump: High PORTA.5
HSerout ["DF",13] ' ask camera to dump frame
'************************************************* *******************
'Store image data at external serial EEPROM
'************************************************* *******************
store3: HSerin [SKIP 7,STR value\80] 'Skip the first 7 charactor then store data to value
Low PORTA.5
c = 1
b = a + 20
For B0 = a TO b ' Loop 60 times
B1 = value[c] ' B1 is data for EEPROM
I2CWrite SDA,SCL,CONT,B0,[B1] ' Write each location
Pause 50 ' Delay 10ms after each write
c = c + 4
Next B0
loop2: For B0 = a TO b STEP 3 ' Loop 8 times
I2CRead SDA,SCL,CONT,B0,[B1,B2,B3] ' Read 3 locations in a row
LCDOut $fe,1,#B0,": ",#B1," ",#B2," ",#B3," " ' Display 2 locations
Pause 2000
Next B0
GoTo RSW
RSW: For row = 21 TO 40 ' Reset window
HSerout ["SW 11 ", DEC row," 30 ", DEC row,13]
Pause 20
HSerout ["DF",13]
HSerin [ SKIP 7, STR value\80] 'Skip the first 7 charactor then store data to value
c = 1
a = a + 20
b = a + 20
For B0 = a TO b ' Loop 60 times
B1 = value[c] ' B1 is data for EEPROM
I2CWrite SDA,SCL,CONT, B0,[B1] ' Write each location
Pause 50
c = c + 4 ' Delay 10ms after each write
Next B0
Next row
show: a = 80
b = 160
For B0 = a TO b STEP 3 ' Loop 8 times
I2CRead SDA,SCL,CONT,B0,[B1,B2,B3] ' Read 3 locations in a row
LCDOut $fe,1,#B0,": ",#B1," ",#B2," ",#B3," " ' Display 2 locations
Pause 2000
Next B0
GoTo loop2
'************************************************* *******************
End
Bookmarks