MHVLib  20111011
An efficiency oriented runtime library for AVR microcontrollers
A:/eclipse/mhvlib/MHV_io_ATmega168.h
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2011, Make, Hack, Void Inc
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions are met:
00007  *  * Redistributions of source code must retain the above copyright
00008  *    notice, this list of conditions and the following disclaimer.
00009  *  * Redistributions in binary form must reproduce the above copyright
00010  *    notice, this list of conditions and the following disclaimer in the
00011  *    documentation and/or other materials provided with the distribution.
00012  *  * Neither the name of the Make, Hack, Void nor the
00013  *    names of its contributors may be used to endorse or promote products
00014  *    derived from this software without specific prior written permission.
00015  *
00016  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
00017  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00018  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00019  * DISCLAIMED. IN NO EVENT SHALL MAKE, HACK, VOID BE LIABLE FOR ANY
00020  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00021  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00022  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00023  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00024  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00025  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00026  */
00027 
00028 
00029 #ifndef MHV_IO_ATMEGA168_H_
00030 #define MHV_IO_ATMEGA168_H_
00031 
00032 #include <avr/io.h>
00033 
00034 // 8 bit timers
00035 //                                       type,                        ctrlRegA,ctrlRegB,overflow1,overflow2,counter,interrupt,intEnable
00036 #define MHV_TIMER8_0 MHV_TIMER_TYPE_5_PRESCALERS, &TCCR0A, &TCCR0B, &OCR0A,   &OCR0B,   &TCNT0, &TIMSK0,  OCIE0A
00037 #define MHV_TIMER8_2 MHV_TIMER_TYPE_7_PRESCALERS, &TCCR2A, &TCCR2B, &OCR2A,   &OCR2B,   &TCNT2, &TIMSK2,  OCIE2A
00038 
00039 #define MHV_TIMER0_INTERRUPTS TIMER0_COMPA_vect, TIMER0_COMPB_vect, 0
00040 #define MHV_TIMER2_INTERRUPTS TIMER2_COMPA_vect, TIMER2_COMPB_vect, 0
00041 
00042 // 16 bit timers
00043 //                                        ctrlRegA,ctrlRegB,ctrlRegC,overflow1,overflow2,overflow3,counter,interrupt,inputCapture1
00044 #define MHV_TIMER16_1 &TCCR1A, &TCCR1B, 0,       &OCR1A,   &OCR1B,   0,        &TCNT1, &TIMSK1,  &ICR1
00045 
00046 #define MHV_TIMER1_INTERRUPTS TIMER1_COMPA_vect, TIMER1_COMPB_vect, 0
00047 
00048 
00049 // USART
00050 //                                 ubrr,   ucsra,   ucsrb,   udr,   rxen,  txen,  rxcie,  txcie,  udre,  u2x
00051 #define MHV_USART0 &UBRR0, &UCSR0A, &UCSR0B, &UDR0, RXEN0, TXEN0, RXCIE0, TXCIE0, UDRE0, U2X0
00052 #define MHV_USART0_INTERRUPTS USART_RX_vect, USART_TX_vect
00053 
00054 #define MHV_AD_RESOLUTION               1024
00055 
00056 #define MHV_AD_REFERENCE_AREF   (uint8_t)(0x00 << 6)
00057 #define MHV_AD_REFERENCE_AVCC   (uint8_t)(0x01 << 6)
00058 #define MHV_AD_REFERENCE_1V1    (uint8_t)(0x03 << 6)
00059 
00060 #define MHV_AD_CHANNEL_0                        0x00
00061 #define MHV_AD_CHANNEL_1                        0x01
00062 #define MHV_AD_CHANNEL_2                        0x02
00063 #define MHV_AD_CHANNEL_3                        0x03
00064 #define MHV_AD_CHANNEL_4                        0x04
00065 #define MHV_AD_CHANNEL_5                        0x05
00066 #define MHV_AD_CHANNEL_6                        0x06
00067 #define MHV_AD_CHANNEL_7                        0x07
00068 #define MHV_AD_CHANNEL_8                        0x08
00069 #define MHV_AD_TEMPERATURE                      0x08
00070 #define MHV_AD_CHANNEL_1V1                      0xfe
00071 #define MHV_AD_CHANNEL_0V                       0xff
00072 
00073 // Power reduction register for ADC
00074 #define MHV_AD_PRR      PRR
00075 
00076 //                                      Dir,    Output, Input,  Bit,PCINT
00077 #define MHV_PIN_B0      &DDRB,  &PORTB, &PINB,  0,      0
00078 #define MHV_PIN_B1      &DDRB,  &PORTB, &PINB,  1,      1
00079 #define MHV_PIN_B2      &DDRB,  &PORTB, &PINB,  2,      2
00080 #define MHV_PIN_B3      &DDRB,  &PORTB, &PINB,  3,      3
00081 #define MHV_PIN_B4      &DDRB,  &PORTB, &PINB,  4,      4
00082 #define MHV_PIN_B5      &DDRB,  &PORTB, &PINB,  5,      5
00083 #define MHV_PIN_B6      &DDRB,  &PORTB, &PINB,  6,      6
00084 #define MHV_PIN_B7      &DDRB,  &PORTB, &PINB,  7,      7
00085 #define MHV_PIN_C0      &DDRC,  &PORTC, &PINC,  0,      8
00086 #define MHV_PIN_C1      &DDRC,  &PORTC, &PINC,  1,      9
00087 #define MHV_PIN_C2      &DDRC,  &PORTC, &PINC,  2,      10
00088 #define MHV_PIN_C3      &DDRC,  &PORTC, &PINC,  3,      11
00089 #define MHV_PIN_C4      &DDRC,  &PORTC, &PINC,  4,      12
00090 #define MHV_PIN_C5      &DDRC,  &PORTC, &PINC,  5,      13
00091 #define MHV_PIN_C6      &DDRC,  &PORTC, &PINC,  6,      14
00092 #define MHV_PIN_D0      &DDRD,  &PORTD, &PIND,  0,      16
00093 #define MHV_PIN_D1      &DDRD,  &PORTD, &PIND,  1,      17
00094 #define MHV_PIN_D2      &DDRD,  &PORTD, &PIND,  2,      18
00095 #define MHV_PIN_D3      &DDRD,  &PORTD, &PIND,  3,      19
00096 #define MHV_PIN_D4      &DDRD,  &PORTD, &PIND,  4,      20
00097 #define MHV_PIN_D5      &DDRD,  &PORTD, &PIND,  5,      21
00098 #define MHV_PIN_D6      &DDRD,  &PORTD, &PIND,  6,      22
00099 #define MHV_PIN_D7      &DDRD,  &PORTD, &PIND,  7,      23
00100 
00101 #define MHV_PIN_TIMER_0_A       MHV_PIN_D6
00102 #define MHV_PIN_TIMER_0_B       MHV_PIN_D5
00103 #define MHV_PIN_TIMER_1_A       MHV_PIN_B1
00104 #define MHV_PIN_TIMER_1_B       MHV_PIN_B2
00105 #define MHV_PIN_TIMER_2_A       MHV_PIN_B3
00106 #define MHV_PIN_TIMER_2_B       MHV_PIN_D3
00107 
00108 #define MHV_INTERRUPT_INT0 INT0_vect, &MCUCR, ISC00
00109 #define MHV_INTERRUPT_INT1 INT1_vect, &MCUCR, ISC10
00110 
00111 #define MHV_PC_INT_COUNT        24
00112 
00113 #define MHV_EEPROM_VECT         EE_READY_vect
00114 
00115 #endif /* MHV_IO_ATMEGA168_H_ */