View previous topic :: View next topic |
Author |
Message |
Robert_d1968
Joined: 18 Dec 2012 Posts: 67 Location: America

|
Posted: Tue Apr 03, 2018 2:18 pm Post subject: Help with sending inputs to serial port |
|
|
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 micro, 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 micro that I used to get this done.
micro:
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 |
|
 |
albertsm
Joined: 09 Apr 2004 Posts: 6198 Location: Holland

|
Posted: Tue Apr 03, 2018 2:30 pm Post subject: |
|
|
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 |
|
 |
EDC
Joined: 26 Mar 2014 Posts: 1136

|
Posted: Tue Apr 03, 2018 3:08 pm Post subject: |
|
|
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 |
|
 |
Robert_d1968
Joined: 18 Dec 2012 Posts: 67 Location: America

|
Posted: Tue Apr 03, 2018 4:06 pm Post subject: |
|
|
@ 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.  |
|
Back to top |
|
 |
albertsm
Joined: 09 Apr 2004 Posts: 6198 Location: Holland

|
Posted: Tue Apr 03, 2018 7:16 pm Post subject: |
|
|
i did provide a sample but maybe you did not recognized it because it is so simple : PRINT bin(PINB); _________________ Mark |
|
Back to top |
|
 |
|