$regfile = "m48def.dat"
$crystal = 8000000
$hwstack = 32
$swstack = 32
$framesize = 32
'AT93C46D-PU > '64x16 PIN ORG to VCC * PIN 8 VCC * PIN 5 GND
Cs Alias Portc.0 '93c46 pin 1 CS
Config Portc.0 = Output
Pin_in Alias Pinc.3 '93c46 pin 4 DO
Config Portc.3 = Input
Pin_out Alias Portc.2 '93c46 pin 3 DI
Config Portc.2 = Output
Sck Alias Portc.1 '93c46 pin 2 SK
Config Portc.1 = Output
Dim My_data As Word , Got_data As Word , Read_enable As Word
Dim My_93c46 As Long
Declare Sub Write_data_93c46(byval 93c_addr As Byte , Byval 93c_data_in As Word)
Declare Sub Read_data_93c46(byval 93c_addr As Byte )
Declare Sub Setup_93c46()
Cs = 0
Const R_93c46 = &B110 'read
Const W_93c46 = &B101 'write
Read_enable = &B1001100000000000 ' Enable serial EEPROM (EWEN):
Call Setup_93c46() 'allways do this after power on !!!!
Waitms 50
' main
Do
' write data to 93c46
' Write_data_93c46(address , data)
Call Write_data_93c46(50 , 2516) 'sample address 50 data 2516
' read data from 93c46
' Read_data_93c46(address)
Call Read_data_93c46(50) 'sample read address 50
' data read in VAR Got_data
Wait 5
Loop
End
' Enable serial EEPROM 9bits
Sub Setup_93c46()
Cs = 1
Shiftout Pin_out , Sck , Read_enable , 1 , 9 ' write enable command
Cs = 0
Waitms 50
End Sub
' write address and data
Sub Write_data_93c46(byval 93c_addr As Byte , Byval 93c_data_in As Word)
My_93c46 = W_93c46
Shift My_93c46 , Left , 6
My_93c46 = My_93c46 + 93c_addr
Shift My_93c46 , Left , 16
My_93c46 = My_93c46 + 93c_data_in
Shift My_93c46 , Left , 7
Cs = 1
Shiftout Pin_out , Sck , My_93c46 , 1 , 25 ' address and data
Cs = 0
Waitms 10
End Sub
'read address put it in got_data
Sub Read_data_93c46(byval 93c_addr As Byte )
My_93c46 = R_93c46
Shift My_93c46 , Left , 6
My_93c46 = My_93c46 + 93c_addr
Shift My_93c46 , Left , 23
Cs = 1
Shiftout Pin_out , Sck , My_93c46 , 1 , 9 ' address
Shiftin Pin_in , Sck , Got_data , 1 , 16 ' read data
Cs = 0
waitms 10
End Sub |