Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

problem with pic16f87 Mikrobasic

Status
Not open for further replies.

zkt

Newbie level 4
Joined
Aug 3, 2006
Messages
6
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,312
The following code runs fine when the value of bite is set inside the sub procedure
I2C_send_byte. But when set prior to calling the sub, sda does not change when the code runs in the sub. And scl changes properly inside and outside the sub. Of the two ways of writing the IF line neither one works. I am stuck.
Any help appreciated.
Code:
program Sunday
' pic 16F87
dim bite,bit,tmp as byte
'dim const tda_adr as byte=%10001000
sub procedure I2C_send_byte
'bite=%10101010    excluding this line causes sda to not change
for bit= 0 to 7
trisb=0
delay_us(50)
         'If ((bite AND 128)=128) Then
        if bite and 128=128 then
        trisa=128                  'set tda high if current tda_data bit is high
        else trisa=0           ' else set tda low
        end if
        bite=bite<< 1    ' shift current tda_data bit to MSB of byte being sent
delay_us(50)
trisb=1
delay_us(100)
next bit
trisb=0
delay_us(50)
ack:
trisa=128
delay_us(50)
trisb=1
delay_us(100)
trisb=0
delay_us(100)
end sub

main:
osccon=%01100010
while iofs=1
wend                        ' porta.7 sda
cmcon=7
portb.0=0                   ' portb.0 scl
porta.7=0

gosub I2C_start
bite=%10101010
I2C_send_byte
gosub I2C_stop

I2C_Start:
trisb=1     ' trisb=0 => portb is output. since portb=0 portb.7= logic 0
trisa=128
delay_us(50)
trisa=0   ' trisb=128=> portb.7 is input. with nothing to pull the voltage low
delay_us(50)  ' Rpu will will pull the voltage high and portb.7= high
trisb=0
return

i2c_stop:
delay_us(50)
trisb=1
trisa=0
delay_us(50)
trisa=128
delay_us(50)
return
end.
 

Been there
No resolution yet.
bout ready to write it in asm and write Mikrobasic off for good
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top