336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.


의뢰는 instructables.tistory.com/64 로 방문해주세요



http://www.atmel.com/images/doc2467.pdf


▲NewTC 제품 핀아웃

글씨가 너무작아서 안보여서 이거 참고하시면 납땜하실때 편합니다.




▼아래 제품 정보

Reset왼쪽에 D1 (1N4148)

Push버튼 왼쪽에 D2

PA0 PA1각각 D4,D3 (for simple test)

DC Jack 왼쪽에 있는 Blue Button으로 On/Off시킬 수 있다.

Xtal왼편의 Jumper를 위/아래로 선택할 수 있다.

(Built-In Xtal은 8MHz이고, 따로 연결할수 있도록 아래칸은 비어있다.)


▼PCB작업시 필요한 회로(★)

AVR-H128-schematic.pdf


▼ATmega128 Pinout(=핀아웃)



--------왓취독타이머---------------------------------------------------------------

WDTCR :: -    -    -    WDCE    WDE    WDP2    WDP1    WDP0

void WDT_off(void)

{

/* Reset WDT*/

__watchdog_reset();

/* Write logical one to WDCE and WDE */

WDTCR |= (1<<WDCE) | (1<<WDE);  //WatchDog Change Enable와 WatchDog Enable

//두개 비트를 1로 Set시킨다.

/* Turn off WDT */

WDTCR = 0x00;                    //싹다 Reset시킴

}

--------인터럽트-------------------------------------------------------------------------

void Move_interrupts(void)

{

/* Enable change of interrupt vectors */

MCUCR = (1<<IVCE);

/* Move interrupts to boot flash section */

MCUCR = (1<<IVSEL);

}

-------▼69쪽-----풀업------------------------------------------------------------------------

unsigned char i;

...

/* Define pull-ups and set outputs high */

/* Define directions for port pins */

PORTB = (1<<PB7)|(1<<PB6)|(1<<PB1)|(1<<PB0);

DDRB = (1<<DDB3)|(1<<DDB2)|(1<<DDB1)|(1<<DDB0);

/* Insert nop for synchronization*/

__no_operation();

/* Read port pins */

i = PINB;

...

-----▼111쪽----16비트 타이머카운터--------------------------------------------------

The main features are: 

• True 16-bit Design (i.e.,Allows 16-bit PWM) 

• Three Independent Output Compare Units 

• Double Buffered Output Compare Registers 

• One Input Capture Unit 

• Input Capture Noise Canceler 

• Clear Timer on Compare Match (Auto Reload) 

• Glitch-free, Phase Correct Pulse width Modulator (PWM) 

• Variable PWM Period • Frequency Generator 

• External Event Counter 

• Ten Independent Interrupt Sources (TOV1, OCF1A, OCF1B, OCF1C, ICF1, TOV3, OCF3A, OCF3B, OCF3C, and ICF3)


Note that in Atmel® AVR® ATmega103 compatibility mode, 

only one 16-bit Timer/Counter is available (Timer/Counter1). 

Also note that in ATmega103 compatibility mode, the Timer/Counter1 

has two Compare Registers (Compare A and Compare B) only.

기억해라. that in Atmel AVR에서 ATmega103은 호환성 모드,

only 하나 16-bit Timer/Counter만 이용가능하다.

또한 기억해라. that in ATmega103 호환성 모드, the Timer/Counter1은 

갖고있다. 두개 비교 레지스터들을(Compare A and Compare B).

Most register and bit references in this section 

are written in general form. 

A lower case “n” replaces the Timer/Counter number, 

and a lower case “x” replaces the Output Compare unit channel. 

However, when using the register or bit defines in a program, 

the precise form must be used i.e., TCNT1 

for accessing Timer/Counter1 counter value and so on. 

A simplified block diagram of the 16-bit Timer/Counter 

is shown in Figure 46. 

For the actual placement of I/O pins, 

refer to “Pin Configurations” on page 2. 

CPU accessible I/O Registers, including I/O bits and I/O pins, 

are shown in bold. 

The device-specific I/O Register and bit locations 

are listed in the “16-bit Timer/Counter Register Description”

on page 132.

대부분의 레지스터 and 비트 참조들 in this 섹션의

은 씌였다. in 일반적인 폼으로.

소문자 n은 대체한다. the Timer/Counter 넘버를,

and 소문자 x는 대체한다. the 출력 비교 유닛 채널을.

However, when 사용할때 the 레지스터를 of 비트 정의들을 in a 프로그램에서,

the 정확한 폼은 must be 사용되어야한다. i.e., TCNT1

for 접근하기위해 Timer/Counter1 카운터 벨류에 and so on.

A 간략화된 블록 다이어그램 of the 16-bit Timer/Counter

은 보인다. in 그림 46에서.

For the 실제 배치를 위해 of I/O 핀들의,

참조해라 to "핀 구성"을 on 페이지 2의.

CPU 접근가능한 I/O Register들, 포함하며 I/O 비트들을 and I/O 핀들을

은 보인다. in 굵은 글씨로.

The 디바이스 특성 I/O Register and 위치들

은 리스트되있다. the "16비트 타이머/카운터 레지스터 설명"

on 페이지 132에.


Table 30. Port B Pins Alternate Functions

 Port Pin

 Alternate Functions

 PB7

 OC2/OC1C(1) (Output Compare and PWM Output for Timer/Counter2 or Output Compare and PWM Output C for Timer/Counter1)

 PB6

  OC1B (Output Compare and PWM Output B for Timer/Counter1)

 PB5

 OC1A (Output Compare and PWM Output A for Timer/Counter1)

 PB4

 OC0 (Output Compare and PWM Output for Timer/Counter0)

 PB3

 MISO (SPI Bus Master Input/Slave Output)

 PB2

 MOSI (SPI Bus Master Output/Slave Input)

 PB1

  SCK (SPI Bus Serial Clock)

 PB0 SS (SPI Slave Select input)


Table 39. Port E Pins Alternate Functions

 Port Pin

 Alternate Function

 PE7

 INT7/ICP3(1) (External Interrupt 7 Input or Timer/Counter3 Input Capture Pin)

 PE6

  INT6/ T3(1) (External Interrupt 6 Input or Timer/Counter3 Clock Input)

 PE5

 INT5/OC3C(1) (External Interrupt 5 Input or Output Compare and PWM Output C for Timer/Counter3)

 PE4

 INT4/OC3B(1) (External Interrupt4 Input or Output Compare and PWM Output B for Timer/Counter3)

 PE3

 AIN1/OC3A (1) (Analog Comparator Negative Input or Output Compare and PWM Output A for Timer/Counter3)

 PE2

 AIN0/XCK0(1) (Analog Comparator Positive Input or USART0 external clock input/output)

 PE1

  PDO/TXD0 (Programming Data Output or UART0 Transmit Pin)

 PE0

 PDI/RXD0 (Programming Data Input or UART0 Receive Pin)

------112쪽--------------------------------------------------------------------------------

The Timer/Counter (TCNTn), 

Output Compare Registers (OCRnA/B/C), 

and 

Input Capture Register (ICRn) are all 16-bit registers. 

Special procedures must be followed 

when accessing the 16- bit registers. 

특별 절차들은 must be 따라야만 한다.

when 접근할때 the 16비트 레지스터들에.

These procedures are described in the section “Accessing 16-bit Registers” on page 114. 

The Timer/Counter Control Registers (TCCRnA/B/C) 

are 8-bit registers 

and 

have no CPU access restrictions.

예) ▼

TCCR1A |= (1<<COM1A1) | (1<<COM1B1) | (1<<WGM11);    //Non Inverted PWM

TCCR1B |= (1<<WGM13) | (1<<WGM12) ! (1<<CS11) | (1<<CS10)     

//PRESCALER=64 MODE 14(FAST PWM)

Interrupt requests (shorten as Int.Req.) signals are all visible 

in the Timer Interrupt Flag Register (TIFR) 

and 

Extended Timer Interrupt Flag Register (ETIFR). 

All interrupts are individually masked with the Timer Interrupt Mask Register (TIMSK) 

and Extended Timer Interrupt Mask Register (ETIMSK). (E)TIFR and (E)TIMSK are not shown in the figure since these registers are shared by other timer units. 

The Timer/Counter can be clocked internally, via the prescaler

or by an external clock source 

on the Tn pin.

타이머/카운터는 생성된다. prescale 혹은 외부 클락에 의해.

The Clock Select logic block controls which clock source and edge the Timer/Counter uses                                             to increment (or decrement) its value.

The Timer/Counter is inactive when no clock source is selected.

The output from the clock select logic is referred to as the timer clock (clkTn).

The double buffered Output Compare Registers (OCRnA/B/C) are compared with the Timer/Counter value at all time.

The result of the compare can be used by the waveform generator to generate a PWM or variable frequency output on the Output Compare Pin (OCnA/B/C).


▼PWM출력 (=교류) (=Alternate Functions)

ATmega8OCR1A는 ATmega128OC1A와 같다.



-----▼114쪽--Temporary Register-----------------------------------------------------

unsigned int i; 

... 

/* Set TCNTn to 0x01FF */ 

TCNTn = 0x1FF; 

/* Read TCNTn into i */ 

i = TCNTn; 

...

-------▼인터럽트------------------------------------------------------------------------

It is important to notice that accessing 16-bit registers are atomic operations.

atomic operation : 쪼갤 수 없는 연산자

If an interrupt occurs between the two instructions accessing the 16-bit register, 

and the interrupt code updates the temporary register 

by accessing the same or any other of the 16-bit Timer Registers, 

then the result of the access outside the interrupt will be corrupted. 

Therefore, when both the main code and the interrupt code update the temporary register, 

the main code must disable the interrupts during the 16-bit access.

메인코드 & 인터럽트코드가 업데이트할때 임시레지스터를,

그 메인코드는 반드시 disable시켜야한다. the 인터럽트를 during the 16비트 접근동안

unsigned int TIM16_ReadTCNTn( void ) 

unsigned char sreg; 

unsigned int i; 

/* Save global interrupt flag */ 

sreg = SREG; 

/* Disable interrupts */ 

__disable_interrupt(); 

/* Read TCNTn into i */ 

i = TCNTn; 

/* Restore global interrupt flag */ 

SREG = sreg; 

return i; 

}

---------▼116쪽----atomic write------------------------------------------------------

The following code examples show how to do an atomic write of the TCNTn Register contents. Writing any of the OCRnA/B/C or ICRn Registers can be done 

by using the same principle.

따라오는 코드 예제들은 보여준다. how to 하는법 atomic 쓰기 of the TCNTn 레지스터 컨텥츠들의.

쓰기 어떤걸 of the OCRnA/B/C의 or ICRn 레지스터들 can be 완성될수있다. 

by 사용함으로써 the 같은 원리를.


void TIM16_WriteTCNTn( unsigned int i ) 

unsigned char sreg; 

unsigned int i; 

/* Save global interrupt flag */ 

sreg = SREG; 

/* Disable interrupts */ 

__disable_interrupt(); 

/* Set TCNTn to i */ 

TCNTn = i; 

/* Restore global interrupt flag */ 

SREG = sreg; 

}

-------▼SPI통신 Master코드--------------------------------------------------------------

void SPI_MasterInit(void)

{

/* Set MOSI and SCK output, all others input */

DDR_SPI = (1<<DD_MOSI)|(1<<DD_SCK);

/* Enable SPI, Master, set clock rate fck/16 */

SPCR = (1<<SPE)|(1<<MSTR)|(1<<SPR0);

}

void SPI_MasterTransmit(char cData)

{

/* Start transmission */

SPDR = cData;

/* Wait for transmission complete */

while(!(SPSR & (1<<SPIF)))

;

}

-----▼SPI통신 Slave코드-----------------------------------------------------------------

void SPI_SlaveInit(void)

{

/* Set MISO output, all others input */

DDR_SPI = (1<<DD_MISO);

/* Enable SPI */

SPCR = (1<<SPE);

}

char SPI_SlaveReceive(void)

{

/* Wait for reception complete */

while(!(SPSR & (1<<SPIF)))

;

/* Return data register */

return SPDR;

}

------▼134쪽---------------------------------------------------------------------------------

●Bit 1:0 – WGMn1:0: Waveform Generation Mode


------▼176쪽 USART통신 Initialization-----------------------------------------------------

#define FOSC 1843200// Clock Speed

#define BAUD 9600

#define MYUBRR FOSC/16/BAUD-1

void main( void )

{

...

USART_Init ( MYUBRR );

...

}

void USART_Init( unsigned int ubrr )

{

/* Set baud rate */

UBRRH = (unsigned char)(ubrr>>8);

UBRRL = (unsigned char)ubrr;

/* Enable receiver and transmitter */

UCSRB = (1<<RXEN)|(1<<TXEN);

/* Set frame format: 8data, 2stop bit */

UCSRC = (1<<USBS)|(3<<UCSZ0);

}

----▼데이터전송 5~8개 데이터 비트--------------------------------------------------------

void USART_Transmit( unsigned char data )

{

/* Wait for empty transmit buffer */

while ( !( UCSRA & (1<<UDRE)) )

;

/* Put data into buffer, sends the data */

UDR = data;

}

-------▼데이터전송 9개 데이터 비트--------------------------------------------------------

void USART_Transmit( unsigned int data )

{

/* Wait for empty transmit buffer */

while ( !( UCSRA & (1<<UDRE)) )

;

/* Copy 9th bit to TXB8 */

UCSRB &= ~(1<<TXB8);

if ( data & 0x0100 )

UCSRB |= (1<<TXB8);

/* Put data into buffer, sends the data */

UDR = data;

}

----▼데이터수신 5~8개 데이터 비트------------------------------------------------------

unsigned char USART_Receive( void )

{

/* Wait for data to be received */

while ( !(UCSRA & (1<<RXC)) )

;

/* Get and return received data from buffer */

return UDR;

}

--------▼데이터수신 9개 데이터 비트-------------------------------------------------------

unsigned int USART_Receive( void ) 

unsigned char status, resh, resl; 

/* Wait for data to be received */ 

while ( !(UCSRA & (11<<RXC)))

/* Get status and 9th bit, then data */ 

/* from buffer */ 

status = UCSRA; 

resh = UCSRB; 

resl = UDR; 

/* If error, return -1 */

if ( status & (1<<FE)|(1<<DOR)|(1<<UPE) )

return -1;

/* Filter the 9th bit, then return */

resh = (resh >> 1) & 0x01; 

return ((resh << 8) | resl); 

}

----▼183쪽 Flushing the Receive Buffer-------------------------------------------------

void USART_Flush( void )

{

unsigned char dummy;

while ( UCSRA & (1<<RXC) ) dummy = UDR;

}

-----▼192쪽 USART Baud Rate Registers – UBRRnL and UBRRnH----------------------------



• Bit 11:0 – UBRRn11:0: USARTn Baud Rate Register 

This is a 12-bit register which contains the USARTn baud rate. 

The UBRRnH contains the four most significant bits, 

and the UBRRnL contains the eight least significant bits of the USARTn baud rate. 

Ongoing transmissions by the transmitter and receiver 

will be corrupted if the baud rate is changed.

진행하는 전송들 by the 송수신부에의해

은 will be 손상된다. if the 보드 레이트가 바뀌면.

Writing UBRRnL will trigger an immediate update of the baud rate prescaler.

쓰기 UBRRnL은 will 트리거할것이다. 즉시 업데이트를 of the 보드 레이트 프리스케일러의

------▼211쪽 TWI---------------------------------------------------------------------

TWCR = (1<<TWINT)|(1<<TWSTA)| (1<<TWEN)

while (!(TWCR & (1<<TWINT))) ;

if ((TWSR & 0xF8) != START) ERROR();

TWDR = SLA_W;

TWCR = (1<<TWINT) | (1<<TWEN);

while (!(TWCR & (1<<TWINT))) ;

if ((TWSR & 0xF8) != MT_SLA_ACK) ERROR();

TWDR = DATA;

TWCR = (1<<TWINT) | (1<<TWEN);

while (!(TWCR & (1<<TWINT))) ;

if ((TWSR & 0xF8) != MT_DATA_ACK) ERROR();

TWCR = (1<<TWINT)|(1<<TWEN)| (1<<TWSTO);



------▼244쪽 ADCSRA---------------------------------------------------------------------

ADCSRA : ADC Control and Status Register A  이다.

ADCSRA=(1<<ADEN)|(1<<ADPS2)|(1<<ADPS1)|(1<<ADPS0); 의 형태로 주로 사용한다.

ADEN : ADC Enable Bit (필수로 1로 Set 시켜야한다.)

ADSC : ADC Start Conversion

In Single Conversion mode,

write this bit to one to start each conversion.

In Free Running mode,

write this bit to one to start the first conversion.

The first conversion 

after ADSC has been written

after the ADC has been enabled, or if ADSC is written at the same time as the ADC is enabled,

will take 25 ADC clock cycles instead of the normal 13.

This first conversion performs initialization of the ADC.

'AVR > ATmega128 Datasheet' 카테고리의 다른 글

ATMEL042(93C56)  (0) 2018.07.03
JMOD-128-1  (0) 2016.08.13
GS-128B (거상인 제품) ㅁ  (0) 2016.04.20
Posted by ElectricShock
:
BLOG main image
잡동사니들(지극히 개인취향인...) (다른글에도 댓글 부탁해요♥) You May Leave English Messages on GuestBook. by ElectricShock

공지사항

카테고리

분류 전체보기 (782)
Programming(=프로그래밍) (3)
MiDi (2)
Animation (4)
Blender (3D Graphic Program.. (10)
Blendtuts.com (Series) (1)
Blender 기초 팁들 (2)
Processing (디지털미디어과) (2)
Music (1)
Books in the world (0)
Communication(CAN, UART, et.. (12)
MCU Examples (PIC 기반) (7)
Transistor (1)
Mikro C Pro (11)
Mikro Pascal (1)
Proton IDE (0)
Robot (0)
Swift 3D (1)
Dummies Series (1)
All about Hacking (0)
제2 외국어 (1)
PIC 해외서적들 (3)
AVR (25)
PIC (MikroC) (MPLAB) (4)
Assembly (2)
ARM (3)
Arduino (26)
PSpice (1)
Proteus ISIS (14)
CodeVision (2)
FPGA (15)
MPLAB (24)
PCB (the Procedure) (15)
3D Printer (5)
PICKIT3 (6)
Matlab (11)
RaspBerry PI (15)
BeagleBone (1)
Android Studio (17)
졸업작품 (172)
Korea History (0)
Issue(사회) (73)
Multimeter 리뷰 (1)
Oscilloscope (1)
A (34)
B (19)
J (6)
C (32)
P (12)
T (37)
H (12)
I (12)
M (44)
R (5)
E (5)
F (2)
D (9)
O (2)
L (7)
S (9)
W (2)
V (6)
G (14)
Visual C++ or Visual Studio (2)
Android App Development (0)

최근에 올라온 글

최근에 달린 댓글

최근에 받은 트랙백