go away spammer

Author Topic: What is all of this  (Read 2034 times)

0 Members and 1 Guest are viewing this topic.

Offline greasemonkey94Topic starter

  • Jr. Member
  • **
  • Posts: 29
  • Helpful? 1
What is all of this
« on: December 21, 2010, 09:40:23 AM »
Hello,

Sorry for the weird title but i could'nt think of anything else,I really know very little about electronics,
could someone please explain what all of this is??

Code: [Select]
/AVRlib includes
#include "global.h" // include global settings
//#include "buffer.h" // include buffer function library
//#include "uart.h" // include uart function library
//#include "rprintf.h" // include printf function library
//#include "timer.h" // include timer function library (timing, PWM, etc)
#include "a2d.h" // include A/D converter function library

//define port functions; example: PORT_ON( PORTD, 6);
#define PORT_ON( port_letter, number ) port_letter |= (1<<number)
#define PORT_OFF( port_letter, number ) port_letter &= ~(1<<number)
#define PORT_ALL_ON( port_letter, number ) port_letter |= (number)
#define PORT_ALL_OFF( port_letter, number ) port_letter &= ~(number)
#define FLIP_PORT( port_letter, number ) port_letter ^= (1<<number)
#define PORT_IS_ON( port_letter, number ) ( port_letter & (1<<number) )
#define PORT_IS_OFF( port_letter, number ) !( port_letter & (1<<number) )


//************CONFIGURE PORTS************
//configure ports for input or output - specific to ATmega8
void configure_ports(void)
{
DDRC = 0x00;  //configure all C ports for input
PORTC = 0x00; //make sure pull-up resistors are turned off
DDRD = 0xFF;  //configure all D ports for output
DDRB = 0xC7;  //configure B ports 0, 1, 2, 6, 7 for output (google search '0b11000111 to hex')

what is port_letter |= (1<<number), and the rest, how does it work, im sorry it doesnt make any sense to me at all,

and also how do you declare pins as input or output??In arduino its really easy using Pinmode, is it something like 1 for input and 0 for ouput?? what is DDRC,PORTC,DDRD,DDRB, and why do we have to type ob11000111 ??
Im sorry for all the questions ??? i know it must be frustratng to have a complete noob :(.

Thanks

Offline waltr

  • Supreme Robot
  • *****
  • Posts: 1,944
  • Helpful? 99
Re: What is all of this
« Reply #1 on: December 21, 2010, 09:53:57 AM »
Quote
#define PORT_ON( port_letter, number )         port_letter |= (1<<number)
Is a macro. Look them up in your favorite C programming guide.

Offline greasemonkey94Topic starter

  • Jr. Member
  • **
  • Posts: 29
  • Helpful? 1
Re: What is all of this
« Reply #2 on: December 21, 2010, 10:47:32 AM »
Quote
#define PORT_ON( port_letter, number )         port_letter |= (1<<number)
Is a macro. Look them up in your favorite C programming guide.


Hehe, Thanks for the reply , but i know what a macro is, just why that macro is the question I=(1<<number) doesn't make sense to me :(

Offline waltr

  • Supreme Robot
  • *****
  • Posts: 1,944
  • Helpful? 99
Re: What is all of this
« Reply #3 on: December 21, 2010, 01:48:46 PM »
The line at the beginning is an example of the Macro usage:
Quote
//define port functions; example: PORT_ON( PORTD, 6);

They do the following as their names describe:
Turn a port bit on or off
Turn an entire port on or off
compliment all the bits on a port
Return the state of a port bit.

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,703
  • Helpful? 173
    • Society of Robots
Re: What is all of this
« Reply #4 on: December 21, 2010, 08:59:05 PM »
They are called 'bit operations'.

http://docs.hp.com/en/B3901-90007/ch05s04.html
http://en.wikipedia.org/wiki/Bitwise_operation

That code is basically controlling the 8 bit port registers, where each bit represents either an external signal pin (such as where you connect your servos), or some internal state switch (such as setting up the PWM frequency).

Offline Graynomad

  • Full Member
  • ***
  • Posts: 79
  • Helpful? 7
    • Skype - grayn0mad
    • WWW
Re: What is all of this
« Reply #5 on: December 24, 2010, 05:10:24 AM »
Code: [Select]
I=(1<<number)
I = 1 shifted left by "number" bits. So

I=(1<<1) == 00000001 << 1 == 00000010
I=(1<<3) == 00000001 << 3 == 00001000

etc

______
Rob
« Last Edit: December 27, 2010, 04:53:57 AM by Graynomad »
Scattered showers my arse -- Noah, 2348BC.

Offline greasemonkey94Topic starter

  • Jr. Member
  • **
  • Posts: 29
  • Helpful? 1
Re: What is all of this
« Reply #6 on: December 27, 2010, 04:50:35 AM »
Hehe thanks for the reply,
Now i understand,
however last question, what is port c, port d etc

Offline Graynomad

  • Full Member
  • ***
  • Posts: 79
  • Helpful? 7
    • Skype - grayn0mad
    • WWW
Re: What is all of this
« Reply #7 on: December 27, 2010, 04:56:37 AM »
Quote
what is port c, port d etc
Just IO ports on the uC, usually 8 bits (but can be less on really small chips), so for example if you do

out PORTC, 0xAA

eight of the chip's pins will be written to with the pattern 0xAA (10101010)
Scattered showers my arse -- Noah, 2348BC.

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,703
  • Helpful? 173
    • Society of Robots
Re: What is all of this
« Reply #8 on: December 27, 2010, 08:08:53 AM »
The pinout of the Axon:
http://societyofrobots.com/axon/images/640pinout.gif

You'll see letters like PE, PH, PB, PA, etc

That means port E, port H, port B, port A, etc.

After that you'll see a number, for example PE3 is port E #3.

Offline greasemonkey94Topic starter

  • Jr. Member
  • **
  • Posts: 29
  • Helpful? 1
Re: What is all of this
« Reply #9 on: December 27, 2010, 08:41:08 AM »
Thanks everyone , got it :D

 


Get Your Ad Here