View previous topic :: View next topic |
Author |
Message |
kimmi
Joined: 24 Feb 2006 Posts: 1922 Location: Denmark
|
Posted: Mon Feb 06, 2017 4:04 pm Post subject: |
|
|
Hi,
Quote: | read data will be 4000 + count_x
4000 to 4063 |
i have just placed an order and added few 93c46 8-dip
when i get them i try to make the code read/write
it will take a few days before i get them ...
btw , did you connect 93c46 right for Pin_out & Pin_in ?
Code: | Cs Alias Portc.0
Config Portc.0 = Output
Pin_out Alias Pinc.3 <<<<<<<<<<<<<<<<<<<
Config Portc.3 = Input
Pin_in Alias Portc.2 <<<<<<<<<<<<<<<<<<<
Config Portc.2 = Output
Sck Alias Portc.1
Config Portc.1 = Output |
or
Code: | Cs Alias Portc.0
Config Portc.0 = Output
Pin_in Alias Pinc.3 <<<<<<<<<<<<<<<<<<<
Config Portc.3 = Input
Pin_out Alias Portc.2 <<<<<<<<<<<<<<<<<<<
Config Portc.2 = Output
Sck Alias Portc.1
Config Portc.1 = Output |
_________________ / Kim |
|
Back to top |
|
|
jeezywonder
Joined: 19 Jan 2017 Posts: 34 Location: Russia, Vladivostok
|
Posted: Tue Feb 07, 2017 12:37 am Post subject: |
|
|
yeah, i checked, doesnt work anyway |
|
Back to top |
|
|
jeezywonder
Joined: 19 Jan 2017 Posts: 34 Location: Russia, Vladivostok
|
Posted: Tue Feb 07, 2017 3:46 am Post subject: |
|
|
inattention - was always my problem.
Kimmi was right, problem was in wrong ports. What about the code - it works
At the moment im trying to get into "write" section of code. |
|
Back to top |
|
|
jeezywonder
Joined: 19 Jan 2017 Posts: 34 Location: Russia, Vladivostok
|
Posted: Tue Feb 07, 2017 7:32 am Post subject: |
|
|
Kimmi, how to use your "write" code section , to write a data? Show me how to use it , please =)
I mean, if i want to send a command through UART, and tell to MK what i want to write and in which address.
Is it possible?
Becouse as i see the "write section" dont write any data to EEPROM. |
|
Back to top |
|
|
kimmi
Joined: 24 Feb 2006 Posts: 1922 Location: Denmark
|
Posted: Tue Feb 07, 2017 8:45 am Post subject: |
|
|
to write you set address and my_data
Code: |
Address = 1 '<<< the address to write
My_data = 600 '<<< your data to sent
'setup sent data
My_93c46 = W_93c46
Shift My_93c46 , Left , 6
My_93c46 = My_93c46 + Address ' added addtess here
Shift My_93c46 , Left , 16
My_93c46 = My_93c46 + My_data ' My_data wil be here
Shift My_93c46 , Left , 7
Call Write_data_93c46()
Waitms 10 |
to read set address and a word var for data
Code: |
Address = 1 '<<< the address to read
My_93c46 = R_93c46
Shift My_93c46 , Left , 6
My_93c46 = My_93c46 + Address ' added address
Shift My_93c46 , Left , 23
Call Read_data_93c46()
Waitms 10
|
in sub read_data_93C46()
we use
Code: | Shiftin Pin_in , Sck , R_data(count) , 1 , 16 , 40 |
here you can change R_data(count) to the word VAR you like to get data in
sample
Code: |
dim Got_data as word '
Shiftin Pin_in , Sck , got_data , 1 , 16 , 40 |
_________________ / Kim |
|
Back to top |
|
|
jeezywonder
Joined: 19 Jan 2017 Posts: 34 Location: Russia, Vladivostok
|
Posted: Tue Feb 07, 2017 10:46 am Post subject: |
|
|
kimmi wrote: | to write you set address and my_data
Code: |
Address = 1 '<<< the address to write
My_data = 600 '<<< your data to sent
'setup sent data
My_93c46 = W_93c46
Shift My_93c46 , Left , 6
My_93c46 = My_93c46 + Address ' added addtess here
Shift My_93c46 , Left , 16
My_93c46 = My_93c46 + My_data ' My_data wil be here
Shift My_93c46 , Left , 7
Call Write_data_93c46()
Waitms 10 |
to read set address and a word var for data
Code: |
Address = 1 '<<< the address to read
My_93c46 = R_93c46
Shift My_93c46 , Left , 6
My_93c46 = My_93c46 + Address ' added address
Shift My_93c46 , Left , 23
Call Read_data_93c46()
Waitms 10
|
in sub read_data_93C46()
we use
Code: | Shiftin Pin_in , Sck , R_data(count) , 1 , 16 , 40 |
here you can change R_data(count) to the word VAR you like to get data in
sample
Code: |
dim Got_data as word '
Shiftin Pin_in , Sck , got_data , 1 , 16 , 40 |
|
Thanks, mate. I got it.
But how to make a code receive Console(like write what i need and in address that i need) commands though UART?
I thought about
but seems its wrong |
|
Back to top |
|
|
kimmi
Joined: 24 Feb 2006 Posts: 1922 Location: Denmark
|
Posted: Wed Feb 08, 2017 12:45 am Post subject: |
|
|
You can try like this:
Code: | $regfile = "m8def.dat"
$crystal = 8000000
$hwstack = 32
$swstack = 32
$framesize = 32
$baud = 9600
Cs Alias Portc.0
Config Portc.0 = Output
Pin_in Alias Pinc.3
Config Portc.3 = Input
Pin_out Alias Portc.2
Config Portc.2 = Output
Sck Alias Portc.1
Config Portc.1 = Output
'Config Shiftin = New
Const R_93c46 = &B110
Const W_93c46 = &B101
Dim Synch_byte As Byte , My_address As Byte
Dim My_data As Word , Got_data As Word , Read_enable As Word
Dim Check_w As Bit , Check_r As Bit
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()
Declare Sub Menu()
Cs = 0
' Enable serial EEPROM (EWEN):
Read_enable = &B1001100000000000
Call Setup_93c46() 'allways do this after power on !!!!
Waitms 50
Print " 93CXX READ/WRITE DATA DEMO"
Call Menu()
Do
If Ischarwaiting() = 1 Then '
Synch_byte = Waitkey()
'SAVE DATA '
If Synch_byte = 48 Then
Print
Print "STORE DATA.."
Input "ADDRESS + ENTER " , My_address Noecho
Print "ADDR : " ; My_address
Input "DATA + ENTER " , My_data Noecho
Print "DATA : " ; My_data ; " - ADDRESS : " ; My_address ; " ..Wait... "
Waitms 25 '
Set Check_w
End If
'SENT DATA '
If Synch_byte = 49 Then
Print
Print "READ DATA.."
Input "ADDRESS + ENTER " , My_address Noecho
Print "READING ADDR : " ; My_address ; " ..Wait..."
Set Check_r
End If
End If
'FOR SAVE DATA
If Check_w = 1 Then
Check_w = 0
Synch_byte = 0
Call Write_data_93c46(my_address , My_data)
My_address = 0
My_data = 0
Waitms 200
Print "OK" ; Chr(13); 'sent back info its saved with "OK"
Wait 1
Call Menu()
End If
'FOR READ DATA
If Check_r = 1 Then
Check_r = 0
Synch_byte = 0
Call Read_data_93c46(my_address)
Print "READ DATA IS : " ; Got_data
My_address = 0
Got_data = 0
Wait 1
Call Menu()
End If
Loop
End
' Enable serial EEPROM 9bits
Sub Setup_93c46()
Cs = 1
Waitms 1
Shiftout Pin_out , Sck , Read_enable , 1 , 9 , 40 ' write enable command
Cs = 0
Waitms 10
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
Waitus 1
Shiftout Pin_out , Sck , My_93c46 , 1 , 25 , 40 ' 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
Waitus 1
Shiftout Pin_out , Sck , My_93c46 , 1 , 9 , 40 ' address
Shiftin Pin_in , Sck , Got_data , 1 , 16 , 40 ' read data
Cs = 0
Waitms 10
End Sub
Sub Menu()
Print
Print "MENU :"
Print "PRESS 0 = STORE DATA"
Print "PRESS 1 = READ DATA"
Print
End Sub
|
_________________ / Kim |
|
Back to top |
|
|
jeezywonder
Joined: 19 Jan 2017 Posts: 34 Location: Russia, Vladivostok
|
Posted: Wed Feb 08, 2017 7:13 am Post subject: |
|
|
Hi Kimmi,
What i tried to do is send address to EEPROM and the data we want to write. I'm sending by console on another PC.
I searched a help, and found
Seems like it works
Code: | Dim B As Byte
Dim A As Byte
Do
Inputbin B
' For Count = 1 To 64 '128 Step 2 ' 1K: 64*16
' Count_x = Count - 1
My_data = B
Address = 3
'setup sent data
My_93c46 = W_93c46
Shift My_93c46 , Left , 6
My_93c46 = My_93c46 + Address 'Count_x
Shift My_93c46 , Left , 16
'My_data = 4000 + Count_x
My_93c46 = My_93c46 + My_data ' as word
Shift My_93c46 , Left , 7
' Shiftout Pin_out , Sck , My_93c46 , 1 , 25 , 40
'sent
Call Write_data_93c46()
'Next
Wait 5
Loop
End |
I send "001" therefore i writw "001" to third EEPOM memory cell, the same with address and data:
Code: | Do
Inputbin A
Inputbin B
' For Count = 1 To 64 '128 Step 2 ' 1K: 64*16
' Count_x = Count - 1
My_data = 1
Address = B
'setup sent data
My_93c46 = W_93c46
Shift My_93c46 , Left , 6
My_93c46 = My_93c46 + Address 'Count_x
Shift My_93c46 , Left , 16
'My_data = 4000 + Count_x
My_93c46 = My_93c46 + My_data ' as word
Shift My_93c46 , Left , 7
' Shiftout Pin_out , Sck , My_93c46 , 1 , 25 , 40
'sent
Call Write_data_93c46()
'Next
Wait 5
Loop
End |
But how to make the both variables receive data from UART and assign it to "address" and "My_data"?
Code: | Do
Inputbin A
Inputbin B
' For Count = 1 To 64 '128 Step 2 ' 1K: 64*16
' Count_x = Count - 1
My_data = B
Address = A
'setup sent data
My_93c46 = W_93c46
Shift My_93c46 , Left , 6
My_93c46 = My_93c46 + Address 'Count_x
Shift My_93c46 , Left , 16
'My_data = 4000 + Count_x
My_93c46 = My_93c46 + My_data ' as word
Shift My_93c46 , Left , 7
' Shiftout Pin_out , Sck , My_93c46 , 1 , 25 , 40
'sent
Call Write_data_93c46()
'Next
Wait 5
Loop
End
|
|
|
Back to top |
|
|
kimmi
Joined: 24 Feb 2006 Posts: 1922 Location: Denmark
|
Posted: Wed Feb 08, 2017 11:50 am Post subject: |
|
|
did you read help for inputbin ?
Code: | Dim Address As Byte , My_data As Word
Do
Inputbin Address , My_data
'setup sent data
My_93c46 = W_93c46
Shift My_93c46 , Left , 6
My_93c46 = My_93c46 + Address 'Count_x
Shift My_93c46 , Left , 16
My_93c46 = My_93c46 + My_data ' as word
Shift My_93c46 , Left , 7
'sent
Call Write_data_93c46()
'Next
Wait 5
Loop
End |
_________________ / Kim |
|
Back to top |
|
|
jeezywonder
Joined: 19 Jan 2017 Posts: 34 Location: Russia, Vladivostok
|
Posted: Wed Feb 08, 2017 12:56 pm Post subject: |
|
|
kimmi wrote: | did you read help for inputbin ?
Code: | Dim Address As Byte , My_data As Word
Do
Inputbin Address , My_data
'setup sent data
My_93c46 = W_93c46
Shift My_93c46 , Left , 6
My_93c46 = My_93c46 + Address 'Count_x
Shift My_93c46 , Left , 16
My_93c46 = My_93c46 + My_data ' as word
Shift My_93c46 , Left , 7
'sent
Call Write_data_93c46()
'Next
Wait 5
Loop
End |
|
Yeah, how it works btw?
I send a 1st message and it will asign to Address? And second message will assign to My_data? How Inputbin understands which data to aplly and to which variable?
Thanks, kimmi
PS Seems like the topic became popular, 720 views, wow |
|
Back to top |
|
|
kimmi
Joined: 24 Feb 2006 Posts: 1922 Location: Denmark
|
Posted: Wed Feb 08, 2017 6:34 pm Post subject: |
|
|
the Inputbin will wait for 3 bytes
1 byte = address (dim as byte)
2 bytes = data (dim as word) = 2 bytes
????? send message
from terminal program or other mcu ?
if other mcu its :
TX : address 25 data 4001
Code: | Dim Data_rx As Word , Addr As Byte
Data_tx = 4001
Addr = 25
Printbin Addr ; Data_tx |
RX : get address & data
Code: | Dim Address As Byte , My_data As Word
Do
Inputbin Address , My_data
'setup sent data
My_93c46 = W_93c46
Shift My_93c46 , Left , 6
My_93c46 = My_93c46 + Address 'Count_x
Shift My_93c46 , Left , 16
My_93c46 = My_93c46 + My_data ' as word
Shift My_93c46 , Left , 7
'sent
Call Write_data_93c46()
'Next
Wait 5
Loop
End
'you get output as :
'SB OP address data not used
'1 01 011001 0000111110100001 0000000
' 25 4001 dont care
|
_________________ / Kim |
|
Back to top |
|
|
jeezywonder
Joined: 19 Jan 2017 Posts: 34 Location: Russia, Vladivostok
|
Posted: Thu Feb 09, 2017 7:54 am Post subject: |
|
|
kimmi wrote: | the Inputbin will wait for 3 bytes
1 byte = address (dim as byte)
2 bytes = data (dim as word) = 2 bytes
????? send message
from terminal program or other mcu ?
if other mcu its :
TX : address 25 data 4001
Code: | Dim Data_rx As Word , Addr As Byte
Data_tx = 4001
Addr = 25
Printbin Addr ; Data_tx |
RX : get address & data
Code: | Dim Address As Byte , My_data As Word
Do
Inputbin Address , My_data
'setup sent data
My_93c46 = W_93c46
Shift My_93c46 , Left , 6
My_93c46 = My_93c46 + Address 'Count_x
Shift My_93c46 , Left , 16
My_93c46 = My_93c46 + My_data ' as word
Shift My_93c46 , Left , 7
'sent
Call Write_data_93c46()
'Next
Wait 5
Loop
End
'you get output as :
'SB OP address data not used
'1 01 011001 0000111110100001 0000000
' 25 4001 dont care
|
|
I'm sending it from VB Console from another PC, through Com-port. Therefore i need to know which values i need to send, as i get it i have to send 22 bits, First 6 is address the another 16 is write data, OP and SB we dont count cuz we have them in code. On my Console the things equals to this:
Code: | dim Data_tx as word
dim Addr as byte
Data_tx = 5
Addr = 2
|
Want to write 5 in second EEPROM's memory cell, it will looks like?
Code: | ' 000010 0000 0000 0000 0101 ' 22 bits |
Sorry for long explanations from your side, but its really confusing for me to understand |
|
Back to top |
|
|
kimmi
Joined: 24 Feb 2006 Posts: 1922 Location: Denmark
|
Posted: Thu Feb 09, 2017 1:53 pm Post subject: |
|
|
Hi,
This forum is about Bascom not VB
i think i helped you on the right track
so you can finish your project
a little bit of reading will do the rest for you _________________ / Kim |
|
Back to top |
|
|
jeezywonder
Joined: 19 Jan 2017 Posts: 34 Location: Russia, Vladivostok
|
Posted: Fri Feb 10, 2017 1:45 am Post subject: |
|
|
kimmi wrote: | Hi,
This forum is about Bascom not VB
i think i helped you on the right track
so you can finish your project
a little bit of reading will do the rest for you |
Thanks you mate, you helped a lot.
OffTop:
(How can i contact you, in a thanks purpose?) |
|
Back to top |
|
|
kimmi
Joined: 24 Feb 2006 Posts: 1922 Location: Denmark
|
Posted: Fri Feb 10, 2017 2:17 pm Post subject: |
|
|
Hi,
no need for more than thanks !
but you can allways find me in my chat if I'am online _________________ / Kim |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You cannot download files in this forum
|
|