Small Function For Port G Atmega 128 AVR

Go To Last Post
19 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

 

 

This topic has a solution.

vidicicici

Last Edited: Fri. Apr 9, 2021 - 12:36 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

LDS and STS, usually, because PORTG isn't accessible via IN and OUT.
 

There was a previous discussion: https://www.avrfreaks.net/forum/...

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

-

vidicicici

Last Edited: Thu. Apr 8, 2021 - 01:31 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

10k seems a bit high for an LED series resistor ?

 

https://electronicsclub.info/leds.htm#calculate

 

westfw wrote:
LDS and STS, usually, because PORTG isn't accessible via IN and OUT.

or write in C - which takes care of such details for you ...

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

 

 

 

mertksk wrote:
I want to use the first bit as input, but the second bit as output at the same time.

The directions of the pins can be set independently - each bit in the Data Direction Register controls one pin of the corresponding port.

 

See the datasheet for details ...

 

EDIT

 

 

 

EDIT 2

 

Note also that there are code examples in the datasheet; eg,

 

 

 

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
Last Edited: Thu. Apr 8, 2021 - 08:48 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 2

Show us the code you have written already.....

What development tools do you use?

screenshot looks an awefull lot like a Protheus screen, so that implies this is a school project.....

If so, why not ask the teacher, then he will know what parts he did not explain clear enough for you and perhaps other students to understand.

He will also benefit from you asking questions.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

-

vidicicici

Last Edited: Thu. Apr 8, 2021 - 01:31 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

-

vidicicici

Last Edited: Thu. Apr 8, 2021 - 01:31 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

mertksk wrote:
I already defined which languages I use.

I can't see that mentioned anywhere in this thread?

 

my teacher is not my private assistant, and it is not possible for him/her to answer all questions.

That's simply not true - it is certainly the teacher's job to answer questions from students!

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

-

vidicicici

Last Edited: Thu. Apr 8, 2021 - 01:31 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

mertksk wrote:

Okay , you can keep asking your teacher. I do not prefer it, it is better for your mental health if you leave this post.

 

aaaahhhh yet another student who would like us to do his homework/school assignments but the moment we do not comply immediately gets into mental problems.......

 

If you as a student are not able to do this basic task or reading a pin and writing to a pin.... then either someone has not payed attention in class or the Teacher has done a terrible job in explaining.........

The things you are asking us to do for you are the things we tell people to do as a first exercise in learning to code...... and those people are not students who had explanations from teachers that should be clear enough for students to understand, but people who in their own spare free time are playing with electronics and thus have to learn all by themselves. And those people get it done in no time, so I would expect a student to also not have any trouble with this very basic issue.

 

now as a side note this forum is run by enthusiasts not being payed ( unless a student decides to pay someone for doing their homework) and in their own spare time. So be bit less attitude could be very very beneficial for you as the asking party........

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0


Welcome to AVRFreaks!

 

May I make a suggestion: instead of wiring the switch to vcc so when it is closed it presents a high or 1 to the port and requiring a pull down resistor, most Freaks would use the internal pull up with in the AVR, and wire the switch to ground.  Like this:

Now when the switch is open the port pin reads 1, and when the switch is closed, it will read 0, by wiring the LED as shown, a low on the LED port pin will turn on the LED.

So copying the state of the switch pin to the LED pin will accomplish your goal but use fewer external parts, which in the real world, will save manufacturing costs!

The one trick needed to accomplish this, is in addition to setting the Data Direction pins to input/output, you must also enable the internal pull up resistor on your input pin.

From the Data Sheet I/O ports section, tells how to set the DDR register for input/output and the PORT register to enable pull ups.  Good luck with your studies!

Jim

 

 

(Possum Lodge oath) Quando omni flunkus, moritati.

"I thought growing old would take longer"

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

-

vidicicici

Last Edited: Thu. Apr 8, 2021 - 01:32 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I suggest that you lighten your tone or I may be forced to limit your participation here.

 

Moderator.

Ross McKenzie ValuSoft Melbourne Australia

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thank you so much, I handled it in this way for now.

 

ldi r18,0xFE
sts ddrg,r18
lds r20, ping
cbr r20, 254
lsl r20
sts portg,r20

 

I take as first-bit input, the other bits are output. Then, I clear all bits in the register to prevent case any error occurs. Then shift them 1 bit , and send them to portg again. This solves the problem. I do not know if there is a basic way though.

vidicicici

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ping and portg may be case sensitive, so you may need to change to PING and PORTG!

 

 

(Possum Lodge oath) Quando omni flunkus, moritati.

"I thought growing old would take longer"

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You are right. However, I do not insult anybody. What kind of answer does he expect after trying to bully someone? I just gave him the answer. My aim is not to join polemics, but to learn more.

 

 

vidicicici

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'll let you handle this one Ross.

John Samperi

Ampertronics Pty. Ltd.

https://www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Locked.

 

Ross McKenzie ValuSoft Melbourne Australia

Topic locked