Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

Help with sending inputs to serial port

 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR
View previous topic :: View next topic  
Author Message
Robert_d1968

Bascom Member



Joined: 18 Dec 2012
Posts: 64
Location: China

usa.gif
PostPosted: Tue Apr 03, 2018 2:18 pm    Post subject: Help with sending inputs to serial port Reply with quote

Hello everybody,

I'm currently trying to send from an ATMEGA8L to a terminal program the input status of all inputs on the ATMEGA8L to that terminal.

I have set the communication specs to 115200 8, N, 1 and it works good. I have been able to do this in another clone basic, but I want to use Bascom for this project.

What I'm doing now does send the inputs to the serial port, but in the wrong format, Looks like decimal format.

Using Print PINB gives me just that. In mikro, I needed to shift each bit into a variable to display all 8 bits of the input port.

However, I looked at the shift command in Bascom, and I guess I'm not grasping how to use it fully! As of now, I see of no way to use a for next loop to complete this. As an example I will paste some code in here from mikro that I used to get this done.

Mikro:

sub procedure Check_bitsB() '- PortB bit status
'- Loop through PortB Bits 0 throuh 7 and set them in Bvalue
for I = 0 to 7 ' Amount of bits to check
select case PINB.I ' Look at PORTB Bits zero to seven
case 0 ' Shift 1 bit to the left and insert a 0
Bvalue = Bvalue << 1 + %0
case 1 ' Shift 1 bit to the left and insert a 1
Bvalue = Bvalue << 1 + %1
end select
next I
end sub

I have tried to create this in bascom but the shift does not work as I expect it to.

Anybody have a way to solve this, or maybe throw me a bone?

Thanks for any help you can provide,

Robert

PS I would like to do this in Bascom, but I have not enough information on using Shift in or shift out. to me it looks like that is sending information to other pins on the avr, such as bitbang. How Do I implement this in Bascom?

(BASCOM-AVR version : 2.0.8.1 )
Back to top
View user's profile Visit poster's website
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5027
Location: Holland

blank.gif
PostPosted: Tue Apr 03, 2018 2:30 pm    Post subject: Reply with quote

you best should take some time to read the help and look at the samples.
look in the help at : PRINT BIN and HEX and VAL and BINVAL
I think it has been explained a millions times how print works and the difference with chr, and printbin

but to make it simple : just send data with PRINT bin(PINB);

_________________
Mark
Back to top
View user's profile Visit poster's website
EDC

Bascom Expert



Joined: 26 Mar 2014
Posts: 677

poland.gif
PostPosted: Tue Apr 03, 2018 3:08 pm    Post subject: Reply with quote

If you want to simply view inputs of the PORTB in the terminal then use this code. Any change of its state will do the print.
Code:
$regfile = "m8def.dat"
$crystal = 8000000
$hwstack = 64
$swstack = 32
$framesize = 128
$baud 115200

Config Portb = &B00000000 : Portb = &B11111111              'whole port is input, whole port has pullup`s enabled

Dim Port_state As Byte , Old_state As Byte


Do

 Port_state = Pinb
 If Old_state <> Port_state Then                            'any change on the port will do the print but only once
  Old_state = Port_state
  Print Bin(port_state)
 End If

Loop


But if you want to do the "animation" shifts then code must be different.
Back to top
View user's profile Visit poster's website
Robert_d1968

Bascom Member



Joined: 18 Dec 2012
Posts: 64
Location: China

usa.gif
PostPosted: Tue Apr 03, 2018 4:06 pm    Post subject: Reply with quote

@ albertsm

Yes I see your point, I have not looked at the newest documents, my bad on that one.

But a little code example would have been better than the explanation given.

There are still little guys here that don't use this on a dally basis.... I know you must have heard this millions of times, still some sample code is in my way, the way to go. Maybe it does not solve the issue, but gives a starting place to work from...

Thanks for the info you did provide. Smile
Back to top
View user's profile Visit poster's website
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5027
Location: Holland

blank.gif
PostPosted: Tue Apr 03, 2018 7:16 pm    Post subject: Reply with quote

i did provide a sample but maybe you did not recognized it because it is so simple : PRINT bin(PINB);
_________________
Mark
Back to top
View user's profile Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
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