Code:
'
' Device configuration fuses
' ==========================
' 4MHz Clock ---------> XT
' WatchDog Timer ---------> ON
' PowerUp Timer ---------> ON
' BrowOut Detect ---------> ON
' LowVoltage programming -> OFF
'
@ __CONFIG _XT_OSC & _WDT_ON & _PWRTE_ON & _BODEN_ON & _LVP_OFF
'
' ---------------------------------------------------------------
' If you're using PM assembler, you must change the above line
' for the following
'
' @ DEVICE PIC16F877A, XT_OSC, WDT_ON, PWRT_ON, BOD_ON, LVP_OFF
' ---------------------------------------------------------------
'
' Hardware configuration
' ======================
'
' I/O PORT
' --------
TRISC = %10000000
TRISD = 0
TRISE = 0
'
' USART
' -----
' Baudrate = 19200
'
DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
DEFINE HSER_TXSTA 24h ' Enable transmit, BRGH = 1
DEFINE HSER_SPBRG 12 ' 19200 Baud @ 4MHz, 0.16%
'
' ADC
' ---
ADCON1 = 7 ' set all related i/o to digital
'
' Hardware assignments
' ====================
'
' I2C BUS
' -------
' 4.7K (or less) pull-up resistor on SDA & SCL line
'
' 24LC512
' -------
' A0 - A2 pin -> GND
' WP pin ------> GND
'
SDA var PORTC.4 ' I2C bus SDA line
SCL var PORTC.3 ' I2C bus SCL line
'
' LCD
' ---
' 4 bits mode
' Data DB<7:4> -> PORTD<7:4>
' RS -----------> PORTE.0
' E ------------> PORTE.1
' R/W ----------> GND
' Vo -----------> 10-20K Trim pot wiper
'
DEFINE LCD_DREG PORTD ' LCD data port
DEFINE LCD_DBIT 4 ' LCD data starting bit
DEFINE LCD_RSREG PORTE ' LCD register select port
DEFINE LCD_RSBIT 0 ' LCD register select bit
DEFINE LCD_EREG PORTE ' LCD enable port
DEFINE LCD_EBIT 1 ' LCD enable bit
DEFINE LCD_BITS 4 ' LCD data bus size
DEFINE LCD_LINES 2 ' Number lines on LCD
DEFINE LCD_COMMANDUS 2000 ' Command delay time in us
DEFINE LCD_DATAUS 50 ' Data delay time in us
'
' Internal EEPROM assignement
' ===========================
data @0, "Good",13,10
data "Bad ",13,10
'
' Variable definition
' ===================
ADDR var word
Data_READ var byte
Data_Write var byte
IsBad var bit
TotalBad var word
PicEepromAddr var byte
Char var byte
'
' Software constants
' ==================
Control con $A0 ' 24LC512 control byte
'
' Program start
' =============
'
' Hardware and software initialisation
' ------------------------------------
PORTC = 0
PORTD = 0
PORTE = 0
clear ' clear all variable
pause 500 ' LCD start-up delay
lcdout $FE,1 ' clear LCD
'
' Send repport header via serial communication
' --------------------------------------------
hserout [" ADDR Data_Write Data_READ Good/Bad",13,10,_
" ---- ---------- --------- --------",13,10]
'
' EEPROM write, read & test loop
' ------------------------------
' 1) write to EEPROM the LowByte value of current
' address (ADDR) value.
'
' 2) read it back and compare results
' case it's different:
' set 'IsBad' flag bit
' increment 'TotalBad' variable value
'
' 3) Show results on LCD
'
' 4) Send results via serial communication @ 19200 bauds
'
For addr=0 to $FFFF
IsBad=0 ' set as good results
data_write=addr.lowbyte ' get the LowByte of current EEPROM
' address
I2CWRITE sda,scl,control,ADDR,[data_write] : PAUSE 5
' send it to the EEPROM and
' wait max Twc delay
I2CREAD sda,scl,control,ADDR,[Data_read]
' read the current data
' at the current address
if data_read != data_write then ' data stored is different?
' YES!
IsBad = 1 ' set bad result flag
totalbad = totalbad + 1 ' increment total of bad result
endif
'
' Show data on LCD
' ----------------
lcdout $FE,2,"W:",hex4 data_write," R:",hex4 data_read,_
$FE,$C0,"TotalBad=", dec totalbad
'
' Send data via serial communication
' ----------------------------------
'
' Show : Current address
' Data_Write
' Data_read
'
hserout [rep " "\4,hex4 addr, rep " "\7, hex4 data_write ,_
rep " "\10,hex4 Data_read,rep " "\8]
'
' Show if the actual reading is "Good"
' or "Bad"
'
for piceepromaddr=(IsBad*6) to ((IsBad*6)+5)
read piceepromaddr, char ' read character from PIC EEPROM
hserout [char] ' send it
next
next
'
' *******************************
' * the whole job is done *
' *******************************
'
' Show the amount of bad results
' ------------------------------
hserout [rep " "\4,rep "="\43,13,10,_
rep " "\4,"TotalBad = ",dec totalbad,13,10]
lcdout $FE,1,"TotalBad=",dec totalbad
SpinHere:
goto spinhere ' spin in round forever
Bookmarks