Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

1wire simualtion with oshon?

Status
Not open for further replies.

SwingeyP

Member
Does anyone have a plugin for oshon that will simulate 1wire comms?

Is there any other way of doing it? - If not does the following code make sense?

Sorry lots of questions there but i hope you'll get the idea.

<code>
'- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -
'lcd program written by paul swingewood
'June 2010
'--------------------------------------------------------------------------



AllDigital

Define LCD_BITS = 8
Define LCD_DREG = PORTB
Define LCD_DBIT = 0
Define LCD_RSREG = PORTA
Define LCD_RSBIT = 0
Define LCD_EREG = PORTA
Define LCD_EBIT = 2
Define LCD_RWREG = PORTA
Define LCD_RWBIT = 1
Define LCD_READ_BUSY_FLAG = 1


Define LCD_COMMANDUS = 5000 'delay after LCDCMDOUT, default value is 5000
Define LCD_DATAUS = 100 'delay after LCDOUT, default value is 100
Define LCD_INITMS = 20

Define 1WIRE_REG = PORTA
Define 1WIRE_BIT = 3

Dim menucode As Byte
Dim gait As Byte
Dim speed As Byte
Dim mode As Byte


1wireInit
WaitMs 1
1wireGetByte menucode


startup:
Lcdinit LcdCurBlink
Lcdcmdout LcdClear
1wireInit
WaitMs 1

start:
1wireGetByte menucode, gait, speed, mode
Select Case menucode
Case 1
Gosub mainmenu
Case 2
Gosub runmenu
Case 3
Gosub setupmenu
EndSelect

Goto start

End

mainmenu:
Lcdcmdout LcdLine1Pos(3)
Lcdout "INSECT-A-BOT"
Lcdcmdout LcdLine2Home
Lcdout "RUN SETUP DEMO"
Return

runmenu:
Lcdcmdout LcdLine1Pos(3)
Lcdout "INSECT-A-BOT"
Lcdcmdout LcdLine2Home
Lcdout "GT"
Lcdout #gait
Return

setupmenu:
Lcdcmdout LcdLine1Pos(3)
Lcdout "INSECT-A-BOT"
Lcdcmdout LcdLine2Home
Lcdout "GAIT SPEED MODE"
Return
</code>
 
hi,
Have you run the code in Oshonsoft.?
I write modules for the Sim, never had need for a 1wire module.
What device are you using as the 1wire source.?
 
Last edited:
Hello again Eric. This all stems from my robot project. The idea is to have a pic which I will call the 'brain'. The brain will get inputs from a set of switches and send a 1 wire communication to the lcd control pic. This pic will really just store the different menus, error messages, and anyting else I can think of. It's a bit of an overshoot but it all fits in with the idea of multiplexing several modules to a common bus further down the page.

In answer to your question. Yes I tried it in oshon and it all works if I set the values like
start:
1wireGetByte menucode, gait, speed, mode
menucode = 2
gait = 3
speed = 2
mode = 3
Select Case menucode
Case 1
Gosub ma


I just wondered if there was a way of simulating what comes on that 1 wire comms. I was just about to wire to pics togethor on some vero board and try that to see what happened. The brain pic just sending random 1wire messages which should then be picked up by the lcd control pic. I hope all this is making sense.

Regards - Paul
 
hi Paul,
What is the 1wire sender type number.?
Your code looks ok, its in line with what the Oshonsoft manual says for the 1wire Basic
 
Hi Eric, It will just be another PIC. Probably a 16f876A for the brain. This pic will send 1wire comms and the other pic (LCD module) will recieve it. There is no need (at the moment) for handshaking. I hope you get the idea now. One pic (brain) sending a 1wire comms to another pic (LCD module) - The code above uses PORTA.3 for receive so I guess I could use the same on the other pic but any pin will do.
 
Ok I gave up on the 1wire and decided to go for serin/out. I never knew you could make this work on any pin. I have to say pic basic makes life a lot easier at times. This is what I have -all working.

BRAIN CODE
AllDigital

Config RA0 = Input
Config RA1 = Input
Config RA2 = Input
Config RA3 = Input
Config RA4 = Output
Config RA5 = Output

Config PORTB = Output

Config portc = Output

Define SEROUT_DELAYUS = 5000

start:
Serout PORTB.7, 4800, 1, 0, 0, 0
WaitMs 2000

Serout PORTB.7, 4800, 2, 1, 2, 3
WaitMs 2000

Serout PORTB.7, 4800, 3, 0, 0, 0
WaitMs 2000
Goto start

End


LCD MODULE CODE

'- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -
'lcd program written by paul swingewood
'June 2010
'--------------------------------------------------------------------------



AllDigital

Define LCD_BITS = 8
Define LCD_DREG = PORTB
Define LCD_DBIT = 0
Define LCD_RSREG = PORTA
Define LCD_RSBIT = 0
Define LCD_EREG = PORTA
Define LCD_EBIT = 2
Define LCD_RWREG = PORTA
Define LCD_RWBIT = 1
Define LCD_READ_BUSY_FLAG = 1


Define LCD_COMMANDUS = 5000 'delay after LCDCMDOUT, default value is 5000
Define LCD_DATAUS = 100 'delay after LCDOUT, default value is 100
Define LCD_INITMS = 20

Define SEROUT_DELAYUS = 5000

Dim menucode As Byte
Dim gait As Byte
Dim speed As Byte
Dim mode As Byte

startup:
Lcdinit LcdCurBlink
Lcdcmdout LcdClear
1wireInit
WaitMs 20

gait = 0
speed = 0
mode = 0

start:
Gosub getdata

Select Case menucode
Case 1
Gosub mainmenu
Case 2
Gosub runmenu
Case 3
Gosub setupmenu
EndSelect

Goto start

End

getdata:
Serin PORTA.3, 4800, menucode, gait, speed, mode
WaitMs 500
Return

mainmenu:
Lcdcmdout LcdLine1Clear
Lcdcmdout LcdLine1Pos(3)
Lcdout "INSECT-A-BOT"
Lcdcmdout LcdLine2Clear
Lcdcmdout LcdLine2Pos(2)
Lcdout "RUN SETUP DEMO"
Return

runmenu:
Lcdcmdout LcdLine1Clear
Lcdcmdout LcdLine1Pos(3)
Lcdout "INSECT-A-BOT"
Lcdcmdout LcdLine2Clear
Lcdcmdout LcdLine2Home
Lcdout "GT"
Lcdcmdout LcdLine2Pos(4)
Lcdout #gait
Lcdcmdout LcdLine2Pos(6)
Lcdout "SPD"
Lcdcmdout LcdLine2Pos(10)
Lcdout #speed
Lcdcmdout LcdLine2Pos(12)
Lcdout "MDE"
Lcdcmdout LcdLine2Pos(16)
Lcdout #mode
Return

setupmenu:
Lcdcmdout LcdLine1Clear
Lcdcmdout LcdLine1Pos(3)
Lcdout "INSECT-A-BOT"
Lcdcmdout LcdLine2Clear
Lcdcmdout LcdLine2Home
Lcdout "GAIT SPEED MODE"
return

As always many thanks for the help.
 
hi Paul,
If you move the serin to PORTA.4, [tmr0] you can use ON INTERRUPT for the serial in.
Code fragment.
Code:
Dim menucode As Byte
Dim gait As Byte
Dim speed As Byte
Dim mode As Byte

OPTION_REG = 0x30  'tmr0, ext clock,high to low,
INTCON.TMR0IE = 1  'set tmr0 interrupt
INTCON.TMR0IF = 0  'clear an existing tmro flag
TMR0 = 0xff  'load timer0 with 255, intr on next high to low

startup:
Lcdinit LcdCurBlink
Lcdcmdout LcdClear

gait = 0
speed = 0
mode = 0

Enable  'enable interrupts

'for my use only
Serout PORTA.2, 4800, "OK", CrLf  'for serial tx test only

start:
Select Case menucode
Case 1
Gosub mainmenu
Case 2
Gosub runmenu
Case 3
Gosub setupmenu
EndSelect
menucode = 0
Goto start

End          
''''''''''''''''''''''''''''''''''''''                                     
'you may want to add save system
On Interrupt

getdata:
INTCON.TMR0IF = 0  'clear inter flag
Serin PORTA.4, 4800, menucode, gait, speed, mode
TMR0 = 0xff  'reload tmr0 with 255
Resume                                            
'''''''''''''''''''''''''''''''''''''''''''''
 
Many thanks for that Eric. Interupts were something in the back of my mind for a while. I'm going to have a readup and see how they can improve further code i've written.
 
Status
Not open for further replies.

Latest threads

Back
Top