Newbie problems/de

From MCS Wiki AVR
< Newbie problems
Revision as of 21:06, 15 February 2013 by Admin (Talk | contribs)
Jump to: navigation, search

== (**COPIED FROM ENGLISH PAGE**) ==When you are using the AVR without knowledge of the architecture you can experience some problems.

 

-I can not set a pin high or low

-I can not read the input on a pin

 

The AVR has 3 registers for each port. A port normally consists of 8 pins. A port is named with a letter from A-F. All parts have PORTB.

 

When you want to set a single pin high or low you can use the SET and RESET statements. But before you use them the AVR chip must know in which direction you are going to use the pins.

 

Therefore there is a register named DDRx for each port. In our sample it is named DDRB. When you write a 0 to the bit position of the pin you can use the pin as an input. When you write a 1 you can use it as output. You can also use CONFIG PORTX.Y= INPUT|OUTPUT

 

After the direction bit is set you must use either the PORTx register to set a logic level or the PINx register to READ a pin level.

 

Yes the third register is the PINx register. In our sample, PINB.

 

 

For example we like to use PORTB.7 as an OUTPUT pin:

CONFIG PORTB.7=OUTPUT  ' will write a '1' to DDRB.7

SET PORTB.7                    ' will set the MS bit to +5V

RESET PORTB.7                 ' will set MS bit to 0 V

 

When using a PIN in INPUT mode, you can also activate an internal pull up resistor. Pull up means that the pin is connected with a resistor to VCC.

To enable the pull up resistor, you need to write a '1' to the PORT register.

 

Example to read PORTB.0 pin :

CONFIG PORTB.0=INPUT ' clears DDRB.0

PORTB.0=1 ' activate pull up

Print PINB.0 'will read LS bit and send it to the RS-232

 

You may also read from PORTx but it will return the value that was last written to it and not the input of the pin.

 

 

To read or write whole bytes use :

PORTB = 0 'write 0 to register making all pins low

PRINT PINB 'print input on pins

 

 

I want to write a special character but they are not printed correct:

 

Well this is not a newbie problem but I put it here so you could find it.

Some ASCII characters above 127 are interpreted wrong depending on country settings. To print the right value use : PRINT "Test{123}?"

 

The {xxx} will be replaced with the correct ASCII character.

 

You must use 3 digits otherwise the compiler will think you want to print {12} for example. This should be {012}

 

 

My application was working but with a new micro it is slow and print funny

 

Most new micro’s have an internal oscillator that is enabled by default. As it runs on 1 or 4 or 8 MHz, this might be slower or faster then your external crystal. This results in slow operation.

 

As the baud rate is derived from the clock, it will also result in wrong baud rates.

 

Solution : change frequency with $crystal so the internal clock will be used.

Or change the fuse bits so the external xtal will be used.

 

 

Some bits on Port C are not working

Some chips have a JTAG interface. Disable it with the proper fuse bit . Or use DISABLE JTAG in your code.

 

Languages   English Deutsch  
Personal tools
Namespaces
Variants
Actions
Navigation
In other languages
Language