Modes of Operation

Normal Mode
The simplest mode of operation is the normal mode (WGM01:0 = 0). In this mode the counting direction is always up (incrementing), and no counter clear is performed. The counter simply overruns when it passes its maximum 8-bit value (TOP = 0xFF) and then restarts from the bottom (0x00). In normal operation the Timer/Counter overflow flag (TOV0) will be set in the same timer clock cycle as the TCNT0 becomes zero. The TOV0 flag in this case behaves like a ninth bit, except that it is only set, not cleared. However, combined with the timer overflow interrupt that automatically clears the TOV0 flag, the timer resolution can be increased by software. There are no special cases to consider in the normal mode, a new counter value can be written anytime.
The output compare unit can be used to generate interrupts at some given time. Using the output compare to generate waveforms in normal mode is not recommended, since this will occupy too much of the CPU time.
가장 단순한 작동은 노말모드 입니다 (WGM01:0 =0). 이 모드에서는 카운팅 방향은 항상 위쪽이며(증가), 카운터 클리어가 수행되지 않습니다. 카운터는 8bit 최대값을 넘어설때 (0xFF) 단순히 초과해 버리며 바닥(0x00) 부터 재시작 합니다. 


Clear Timer on Compare Match (CTC) Mode
In Clear Timer on Compare or CTC mode (WGM01:0 = 2), the OCR0 Register is used to manipulate the counter resolution. In CTC mode the counter is cleared to zero when the counter value(TCNT0) matches the OCR0. The OCR0 defines the top value for the counter, hence also its resolution. This mode allows greater control of the compare match output frequency. It also simplifies the operation of counting external events. The timing diagram for the CTC mode is shown in Figure 38. The counter value (TCNT0) increases until a compare match occurs between TCNT0 and OCR0, and then counter (TCNT0) is cleared. 
CTC 모드에서 OCR0 레지스터는 카운터 해상도를 조작하는데 사용됩니다. CTC 모드에서 카운터는 카운터 값(TCNT0)가 OCR0와 일치할때 0으로 초기화 됩니다. OCR0는 상한값과 해상도를 정의합니다. 이 모드는 compare match 출력 주파수의 더 나은 제어를 제공합니다. 그것은 또한 외부 이벤트의 카운팅 작업을 단순화 시킵니다. CTC 모드를 위한 타이밍 다이너그램은 Figure 38에 있습니다. 카운터 값(TCNT0)는 TCNT0와 OCR0 값이 일치하는 순간때까지 증가하며 카운터는(TCNT0) 초기화 됩니다.


Fast PWM Mode
The fast Pulse Width Modulation or fast PWM mode (WGM01:0 = 3) provides a high frequency PWM waveform generation option. The fast PWM differs from the other PWM option by its single-slope operation. The counter counts from BOTTOM to MAX then restarts from BOTTOM. In non-inverting Compare Output mode, the output compare (OC0) is cleared on the compare match between TCNT0 and OCR0, and set at BOTTOM. In inverting Compare Output mode, the output is set on compare match and cleared at BOTTOM. Due to the single-slope operation, the operating frequency of the fast PWM mode can be twice as high as the phase correct PWM mode that uses dual-slope operation. This high frequency makes the fast PWM mode well suited for power regulation, rectification, and DAC applications. High frequency allows physically small sized external components (coils, capacitors), and therefore reduces total system cost. In fast PWM mode, the counter is incremented until the counter value matches the MAX value. The counter is then cleared at the following timer clock cycle. The timing diagram for the fast PWM mode is shown in Figure 39. The TCNT0 value is in the timing diagram shown as a histogram for illustrating the single-slope operation. The diagram includes non-inverted and inverted PWM outputs. The small horizontal line marks on the TCNT0 slopes represent compare matches between OCR0 and TCNT0.
빠른 PWM 모드는 고주파 PWM 파형을 생성하는 옵션을 제공합니다. 빠른 PWM은 다른 PWM 옵션들에 비해 single-slope 작동으로 인해 차이점이 존재합니다. 카운터는 바닥에서 최대값으로 세고 바닥에서 다시 시작합니다(0 -> 0xFF / 증가).
non-inverting 비교 출력 모드에서는 출력비교(OC0)는 TCNT0와 OCR0가 일치할때 초기화 되고, 바닥(0x00)에서 설정됩니다.
inverting 비교 출력 모드에서는 일치할때 설정되고 바닥에서 초기화 됩니다. single-slope 작동으로 인해 빠른 PWM 모드의 작동 주파수는 dual-slope 작동을 사용하는 phase correct PWM의 2배 이상을 낼 수 있습니다. 이러한 높은 주파수로 인해 fast PWM 모드는 전력제어, 정류 그리고 DAC 어플리케이션에 매우 적절합니다. 고주파는 물리적으로 작은 크기의 외부 부품(코일, 캐패시터)를 사용할수 있도록 해주고, 전체 시스템의 비용을 낮출수 있습니다. 빠른 PWM 모드에서 카운터는 카운터 값이 최대값과 일치할때 까지 증가합니다. 카운터는 따라오는 타이머 클럭 사이클에 초기화 됩니다. 



Phase Correct PWM Mode
The phase correct PWM mode (WGM01:0 = 1) provides a high resolution phase correct PWM waveform generation option. The phase correct PWM mode is based on a dual-slope operation. The counter counts repeatedly from BOTTOM to MAX and then from MAX to BOTTOM. In non-inverting Compare Output mode, the output compare (OC0) is cleared on the compare match between TCNT0 and OCR0 while counting up, and set on the compare match while downcounting. In inverting Output Compare mode, the operation is inverted. The dual-slope operation has lower maximum operation frequency than single slope operation. However, due to the symmetric feature of the dual-slope PWM modes, these modes are preferred for motor control applications. 
phase correct PWM 모드는 고해상도의 
phase correct PWM 파형을 생성하는 옵션을 제공합니다. phase correct PWM 는 dual-slope 작동에 기반합니다. 카운터는 바닥과 최대값으로 그리고 최대에서 바닥으로 반복적으로 세어지게 됩니다. non-inverting비교 출력 모드에서는 출력 바교(OC0)는 숫자가 세어 올라가는(증가) 중 TCNT0와 OCR0이 일치하는 순간에 초기화 되고, 아래로 세어지는 도중(감소) 비교가 일치할 경우 설정됩니다. inverting  출력 비교 모드에서는 작동이 반대로 됩니다. dual-slope 작동은 single slope 작동보다 낮은 작동 주파수를 가집니다. 하지만 dual-slope PWM 모드의 대칭 특성으로 인해 모터 제어에 적합합니다.
Posted by 구차니
embeded/AVR (ATmega,ATtiny)2013. 12. 31. 08:40
역시 눈에 들어 오는게 최고지 ㅋㅋ
ATmega128에는 총 4개
Atmega8에는 총 3개의 timer/counter가 존재한다.

UI상으로는 Timer1/3이 16bit로 사용가능하며
TCNT1/TCNT3은
TCNT1H / TCNT1L 이런식으로 16bit 로 확장되어 있으나
TCNT1이 TCNT1L과 동일 메모리 주소로 설정되어 8bit/16bit로 사용이 가능해진다.
(Atmega8은 Timer3가 없으며 Timer1이 유일한 16bit 타이머이다)





문제는... Timer는 우선순위가 높아야 하는데 Timer3는 UART0 보다 우선순위가 낮으므로
Timer1 번을 이용해서 16bit Timer를 사용하는게 가장 무난한 선택으로 생각된다. (Timer0 8bit를 포기!)

 
Posted by 구차니
embeded/AVR (ATmega,ATtiny)2013. 12. 30. 23:47
메모리나 플래시 용량이 크지 않은 micom 특성상 용량을 줄이기 위해서 발악을 해야하는데
사소한 팁이라고 해야하려나... 

inline void init_timer(void)
{
TCCR0 = 0x04;     // Prescaler 설정
TCNT0 = OVERFLOW - (F_CPU / TICKS_PER_SEC / Prescaler);// 오버플로우에 사용될 초기값
TIMSK = 0x01;     // 오버플로우 인터럽트 허용
}

int main(void)
{
int idx = 0;
int val = 1500;

DDRB = 0xFF;
PORTB = 0x00;

init_timer();
while(1)
{
;
}

return 0;
}

inline 사용시
AVR Memory Usage
----------------
Device: atmega8

Program:     146 bytes (1.8% Full)
(.text + .data + .bootloader)

Data:          2 bytes (0.2% Full)
(.data + .bss + .noinit)
 

inline 사용시
AVR Memory Usage
----------------
Device: atmega8

Program:     160 bytes (2.0% Full)
(.text + .data + .bootloader)

Data:          2 bytes (0.2% Full)
(.data + .bss + .noinit)

정말 사소한 용량 차이이지만 하나하나 쌓이면 은근 커지기에..
나중에 switch 테스트 예정 
Posted by 구차니
embeded/AVR (ATmega,ATtiny)2013. 12. 30. 19:40
아래와 같이 EEMEM 이라는 접두를 이용해서 선언하면 되는데
avr/eeprom.h를 포함해야 한다.
#include <avr/eeprom.h>
EEMEM char test[128]; 

만약 include 하지 않으면 아래와 같은 에러가 발생한다.
 ../servo.c:29: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'char' 

컴파일 성공시에는 아래와 같이 메시지가 나타나는데
EEPROM 이라는게 추가 되어 나타난다. 
AVR Memory Usage
----------------
Device: atmega8

Program:     392 bytes (4.8% Full)
(.text + .data + .bootloader)

Data:          2 bytes (0.2% Full)
(.data + .bss + .noinit)

EEPROM:      128 bytes (25.0% Full)
(.eeprom) 

[링크 : http://www.nongnu.org/avr-libc/user-manual/group__avr__eeprom.html]
2012/01/03 - [embeded/ATmega/ATtiny (AVR)] - AVR EEPROM / CODE section 관련

Posted by 구차니
embeded/AVR (ATmega,ATtiny)2013. 12. 30. 17:26
1500us 센터 +-800usec 총 1600usec/180degree
아무래도 타이머를 이용한다고 하여도 16MHz 쓰는 이상
1usec 이상의 해상도는 무리라고 판단된다.

1600usec/180도 = 8usec/1도 
1usec = 0.125도

아무튼.. 계산을 해보니
정수형에 의한 오차가 발생할 수 밖에 없지만
0.1도를 한계(angle resolution)로 주고 0.05도 반올림 하여 사용하는게 전반적인 오차가 적을 것으로 생각된다.

 
Posted by 구차니
embeded/AVR (ATmega,ATtiny)2013. 12. 29. 14:14
걍 귀찮아서.. 날로 먹은 소스코드임
일단 거상인 ATmega8 보드와 엘레파츠에서 이제는 매진되버린(!) 서보 모터를 사용함

[링크 : http://www.eleparts.co.kr/EPX33N6R] ES-311
[링크 : http://www.gersangin.com/shop/goods/goods_view.php?&goodsno=1092&category=] ATmega8

AVR Studio 프로젝트 설정시 ATmega8 과 클럭은 8,000,000 Hz(8MHz)로 설정한다.


퓨즈비트는 귀찮으니.. 내부 RC 8MHz 클럭으로.. 물론 보드에 16MHz 외부 크리스탈 있으니
필요하다면 변경하고 위의 주파수를 설정해주면 된다.


일단.. 가장 중요한건.. 전원이 부족해서 USB 파워로는 안될건 뻔하고..
그렇기에 전원을 분리했더니 그라운드가 달라서 오작동을 한다.(미친듯이 왼쪽으로만 끝까지 가버리는...)
그런 이유로 보드에 인가되는 전원 그라운드와 서보에 인가되는 전원 그라운드를 묶어주어야 한다.
(이러면.. 아날로그노이즈가 타고 오지 않으려나? ㅠㅠ)


일단은 GPIO를 이용해서 간단하게 중앙 - 좌 - 중앙 - 우
왕복시키는 코드이다. 이제 갯수도 늘려봐야 하는데 크앙!
서보 특성상 20ms 주기로 PWM 신호를 보내주고
신호의 길이는 1500usec이 neutral(중앙/센터)
+- 800usec인 700usec / 2300usec 범위에서 제어를 한다.

#include < avr/io.h >
#include < avr/interrupt.h >
#include < util/delay.h >

/******************************************/
int main(void)
{
	int idx = 0;
	int val = 1500;

	DDRB = 0xFF;
	PORTB = 0x00;
	
	while(1)
	{
		for(idx = 0; idx < 50; idx++)
		{
			PORTB = 0xFF;
			_delay_us(1500);

			PORTB = 0x00;
			_delay_us(20000 - 1500);
		}

		for(idx = 0; idx < 50; idx++)
		{
			PORTB = 0xFF;
			_delay_us(700);

			PORTB = 0x00;
			_delay_us(20000 - 700);
		}

		for(idx = 0; idx < 50; idx++)
		{
			PORTB = 0xFF;
			_delay_us(1500);

			PORTB = 0x00;
			_delay_us(20000 - 1500);
		}

		for(idx = 0; idx < 50; idx++)
		{
			PORTB = 0xFF;
			_delay_us(2300);

			PORTB = 0x00;
			_delay_us(20000 - 2300);
		}
	}

	return 0;
}
Posted by 구차니
embeded/AVR (ATmega,ATtiny)2013. 12. 27. 20:59
학원 알아보러 가는 김에 겸사겸사
세운상가에 가서 개당 1000원에 구매!
16MHz 짜리를 사려고 했으나 없다고 하셔서 이거라도 일단 get!


동일한 모델이 없어서 고민때리다
대충 오실레이터 잡아서 데이터시트 보고 연결!

[링크 : http://devicemart.co.kr/goods/view.php?seq=5679]

ATtiny 3개중에 2개는 살리고
거상인 ATmega8도 살리고 아싸 조으다 조으다 ㅋㅋㅋ

2013/12/20 - [embeded/ATmega/ATtiny (AVR)] - Atmega8 으앙 쥬금!!! ㅠㅠ


+ 이거 전에 다른 ATmega128에서
 while(1) { PORTA = 0xFF; PORTA=0x00; } 

이런 간략한 소스로 8MHz 정도 나오지 않을까.. 라는 소스를 작성해서 해보았느나
접점의 문제인지 클럭이 깔끔하지 않아서 인지.. 인공호흡 실패 ㅠㅠ 
Posted by 구차니
embeded/AVR (ATmega,ATtiny)2013. 12. 25. 00:41


사용부품
[링크 : http://www.us-technology.co.kr/product/product_main.asp?mode=101&smode=9] v3.0 보드
[링크 : http://devicemart.co.kr/goods/view.php?seq=1075057 ] LC1628 (동일 부품 아닐수도 있음)

참고소스
[링크 : http://www.avrprojects.net/attachments/lcdinterface.c]

참고 데이터시트
[링크 : http://www.ganasys.co.kr/kor/support_board2/pds_file/LC1628-BMDWH6Rev1.0.pdf]



lc1628.h
/*******************************************************
	LC1628 definition
*******************************************************/

/***************** position *****************/
#define	CLCD_RS	0x01
#define	CLCD_RW	0x02
#define	CLCD_E	0x04
#define	CLCD_DA	0xF0

/***************** command *****************/
/* RS R/W = 0x00 */
#define CMD_CLS 0x01	// Clear Display
#define CMD_RTH 0x02	// Return HOME
#define CMD_MOD 0x04	// Entry Mode Set
	#define MOD_INC 0x02
	#define MOD_DEC 0x00
	#define MOD_SHL 0x01
	#define MOD_SHR 0x00
#define CMD_DIS 0x08	// Display on/off
	#define DIS_ON  0x04
	#define DIS_CUR 0x02
	#define DIS_BLK	0x01
#define CMD_CUR 0x10	// Cursor or Display Shift
	#define CUR_CUR 0x08
	#define CUR_ALL	0x00
	#define CUR_LEF 0x04
	#define CUR_RIG 0x00
#define CMD_FNC 0x20	// Function Set
	#define FNC_DL8 0x10
	#define FNC_DL4 0x00
	#define FNC_DN2 0x08
	#define FNC_DN1 0x00
	#define FNC_H10	0x04
	#define FNC_H07	0x00
#define CMD_CGA 0x40	// Set CGRAM Address
	#define CRA_ADR 0x3F
#define CMD_DDA 0x80	// Set DDRAM Address

lc1628.c
#include < stdio.h >
#include < avr/io.h >
#include < util/delay.h >
#include "lc1628.h"

#define DEFAULT_DLY	20

static int uart_putchar(char c, FILE *stream)
{
	if (c == '\n') uart_putchar('\r', stream);
	loop_until_bit_is_set(UCSR0A, UDRE);
	UDR0 = c;

  return 0;
}

static FILE mystdout = FDEV_SETUP_STREAM(uart_putchar, NULL, _FDEV_SETUP_WRITE);


/*************************************************/
void ls1628_write_cmd(char cmd)
{
	/**************************************/
	// set RS & R/W
	PORTC = 0x00;

	// set E clock to high
	_delay_us(DEFAULT_DLY); // 40ns delay
	PORTC |= CLCD_E;

	// data set - high nibble
	PORTC |= (cmd & 0xF0);
	_delay_us(DEFAULT_DLY); // 80ns delay

	// set E clock to low
	PORTC &= (~CLCD_E);
	_delay_us(DEFAULT_DLY); // 10ns delay

	// release RW
	PORTC &= (~CLCD_RW);


	/**************************************/
	// set RS & R/W
	PORTC = 0x00;

	// set E clock to high
	_delay_us(DEFAULT_DLY); // 40ns delay
	PORTC |= CLCD_E;

	// data set - low nibble
	PORTC |= ((cmd & 0x0F) << 4);
	_delay_us(DEFAULT_DLY); // 80ns delay

	// set E clock to low
	PORTC &= (~CLCD_E);
	_delay_us(DEFAULT_DLY); // 10ns delay

	// release RW
	PORTC &= (~CLCD_RW);
}

void ls1628_write_char(char data)
{
	/**************************************/
	// set RS & R/W
	PORTC = CLCD_RS;

	// set E clock to high
	_delay_us(DEFAULT_DLY); // 40ns delay
	PORTC |= CLCD_E;

	// data set - high nibble
	PORTC |= (data & 0xF0);
	_delay_us(DEFAULT_DLY); // 80ns delay

	// set E clock to low
	PORTC &= (~CLCD_E);
	_delay_us(DEFAULT_DLY); // 10ns delay

	// release RW
	PORTC &= (~CLCD_RW);


	/**************************************/
	// set RS & R/W
	PORTC = CLCD_RS;

	// set E clock to high
	_delay_us(DEFAULT_DLY); // 40ns delay
	PORTC |= CLCD_E;

	// data set - low nibble
	PORTC |= ((data & 0x0F) << 4);
	_delay_us(DEFAULT_DLY); // 80ns delay

	// set E clock to low
	PORTC &= (~CLCD_E);
	_delay_us(DEFAULT_DLY); // 10ns delay

	// release RW
	PORTC &= (~CLCD_RW);
}

/*************************************************/
void ls1628_cmd_clear()
{
	ls1628_write_cmd(CMD_CLS);
}

void li1628_cmd_setpos(char y, char x)
{
	// y must 0(1st line) or 1(2nd line)
	ls1628_write_cmd(CMD_DDA | (y * 0x40 + x));
}

void ls1628_write_string(char *data)
{
	int idx = 0;

	while(data[idx] != 0x00)
		ls1628_write_char(data[idx++]);
}

/*************************************************/
void init_clcd(void)
{
	_delay_ms(50);
	ls1628_write_cmd(CMD_FNC | FNC_DL4 | FNC_DN2 | FNC_H07);	// fuction set
	PORTC = CLCD_E; // unknown

	_delay_us(80);	 											// 39 us wait
	ls1628_write_cmd(CMD_DIS | DIS_ON | DIS_CUR | DIS_BLK);		// disp on/off control
	_delay_us(80);	 											// 39 us wait
	ls1628_write_cmd(CMD_CLS);									// disp clear
	_delay_ms(2);												// 1.53ms wait
	ls1628_write_cmd(CMD_MOD | MOD_INC | MOD_SHR);				// entry mode set CMD_MOD
	_delay_us(80);
	ls1628_write_cmd(CMD_DDA);
	_delay_us(80);
}

void init_uart0(void)
{
	/* UART0 115200-N-8-1 */
	UBRR0H = 0;
	UBRR0L = 8; // 115k with U2X = 0
	UCSR0A = 0x00; // U2X = 0;
	UCSR0B = 0xD8;
	UCSR0C = 0x06; //Asyncronous - no parity - 1bits(stop) - 8bits(data)

    stdout = &mystdout;

	printf("\n\n\n\n\n");
}

void init_atmega(void)
{
	DDRC = 0xFF;
	PORTC = 0xFF;

	SFIOR = SFIOR | 0x04;

	init_uart0();
}

int main(void)
{
	init_atmega();
	init_clcd();

	li1628_cmd_setpos(0,3);
	ls1628_write_string("Hello World");
	li1628_cmd_setpos(1,0);
	ls1628_write_string("ATmega128 CLCD");

	return 0;
}

'embeded > AVR (ATmega,ATtiny)' 카테고리의 다른 글

ATmega8 로 ES-311(HS-311) 서보 제어하기  (2) 2013.12.29
ATtiny2313 / ATmega8 인공호흡!  (0) 2013.12.27
ATmega128 + LC1628 제어하기 2  (0) 2013.12.24
ATmega128 + LC1628 제어하기 1  (0) 2013.12.24
lc1628 예제 소스  (0) 2013.12.20
Posted by 구차니
embeded/AVR (ATmega,ATtiny)2013. 12. 24. 23:54
명령어와 데이터 관련 GPIO 제어루틴

귀찮으니 대충 정리해서
명령어는
Step 1. RS/RW가 동시에 Low로 이동 (40ns delay)
Step 2. E가 High로 이동 / Data 설정(상위 4비트)
Step 3. E가 Low로 이동 (10ns delay)
Step 4. RW 해제
 

Step 5. RS/RW가 동시에 Low로 이동
Step 6. E가 High로 이동 / Data 설정 (하위 4비트) - Step 2 반복
Step 7. E가 Low로 이동 (10ns delay) - Step 3 반복
Step 8. RS/RW가 동시에 High로 이동

DDRAM/CGRAM 데이터는
Step 1. RS는 High RW는 Low로 이동 (40ns delay)
Step 2. E가 High로 이동 / Data 설정(상위 4비트)
Step 3. E가 Low로 이동 (10ns delay)
Step 4. RW 해제
 

Step 5. RS는 High RW는 Low로 이동
Step 6. E가 High로 이동 / Data 설정 (하위 4비트) - Step 2 반복
Step 7. E가 Low로 이동 (10ns delay) - Step 3 반복
Step 8. RS/RW가 동시에 High로 이동


#define	CLCD_RS	0x01
#define	CLCD_RW	0x02
#define	CLCD_E	0x04

#define DEFAULT_DLY	20

void ls1628_write_cmd(char cmd)
{
	/**************************************/
	// set RS & R/W
	PORTC = 0x00;

	// set E clock to high
	_delay_us(DEFAULT_DLY); // 40ns delay
	PORTC |= CLCD_E;

	// data set - high nibble
	PORTC |= (cmd & 0xF0);
	_delay_us(DEFAULT_DLY); // 80ns delay

	// set E clock to low
	PORTC &= (~CLCD_E);
	_delay_us(DEFAULT_DLY); // 10ns delay

	// release RW
	PORTC &= (~CLCD_RW);


	/**************************************/
	// set RS & R/W
	PORTC = 0x00;

	// set E clock to high
	_delay_us(DEFAULT_DLY); // 40ns delay
	PORTC |= CLCD_E;

	// data set - low nibble
	PORTC |= ((cmd & 0x0F) << 4);
	_delay_us(DEFAULT_DLY); // 80ns delay

	// set E clock to low
	PORTC &= (~CLCD_E);
	_delay_us(DEFAULT_DLY); // 10ns delay

	// release RW
	PORTC &= (~CLCD_RW);
}

void ls1628_write_char(char data)
{
	/**************************************/
	// set RS & R/W
	PORTC = CLCD_RS;

	// set E clock to high
	_delay_us(DEFAULT_DLY); // 40ns delay
	PORTC |= CLCD_E;

	// data set - high nibble
	PORTC |= (data & 0xF0);
	_delay_us(DEFAULT_DLY); // 80ns delay

	// set E clock to low
	PORTC &= (~CLCD_E);
	_delay_us(DEFAULT_DLY); // 10ns delay

	// release RW
	PORTC &= (~CLCD_RW);


	/**************************************/
	// set RS & R/W
	PORTC = CLCD_RS;

	// set E clock to high
	_delay_us(DEFAULT_DLY); // 40ns delay
	PORTC |= CLCD_E;

	// data set - low nibble
	PORTC |= ((data & 0x0F) << 4);
	_delay_us(DEFAULT_DLY); // 80ns delay

	// set E clock to low
	PORTC &= (~CLCD_E);
	_delay_us(DEFAULT_DLY); // 10ns delay

	// release RW
	PORTC &= (~CLCD_RW);
}

CLCD 초기화는 아래와 같이 수행해 준다.
그런데.. Function set 이후에 왜 E를 High로 해주어야 하는건지... 이유를 모르겠다!!!
#define CMD_CLS 0x01	// Clear Display
#define CMD_RTH 0x02	// Return HOME
#define CMD_MOD 0x04	// Entry Mode Set
	#define MOD_INC 0x02
	#define MOD_DEC 0x00
	#define MOD_SHL 0x01
	#define MOD_SHR 0x00
#define CMD_DIS 0x08	// Display on/off
	#define DIS_ON  0x04
	#define DIS_CUR 0x02
	#define DIS_BLK	0x01
#define CMD_CUR 0x10	// Cursor or Display Shift
	#define CUR_CUR 0x08
	#define CUR_ALL	0x00
	#define CUR_LEF 0x04
	#define CUR_RIG 0x00
#define CMD_FNC 0x20	// Function Set
	#define FNC_DL8 0x10
	#define FNC_DL4 0x00
	#define FNC_DN2 0x08
	#define FNC_DN1 0x00
	#define FNC_H10	0x04
	#define FNC_H07	0x00
#define CMD_CGA 0x40	// Set CGRAM Address
	#define CRA_ADR 0x3F
#define CMD_DDA 0x80	// Set DDRAM Address

void init_clcd(void)
{
	_delay_ms(50);
	ls1628_write_cmd(CMD_FNC | FNC_DL4 | FNC_DN2 | FNC_H07);	// fuction set
	PORTC = CLCD_E; // unknown

	_delay_us(80);	 											// 39 us wait
	ls1628_write_cmd(CMD_DIS | DIS_ON | DIS_CUR | DIS_BLK);		// disp on/off control
	_delay_us(80);	 											// 39 us wait
	ls1628_write_cmd(CMD_CLS);									// disp clear
	_delay_ms(2);												// 1.53ms wait
	ls1628_write_cmd(CMD_MOD | MOD_INC | MOD_SHR);				// entry mode set CMD_MOD
	_delay_us(80);
	ls1628_write_cmd(CMD_DDA);
	_delay_us(80);
}

'embeded > AVR (ATmega,ATtiny)' 카테고리의 다른 글

ATtiny2313 / ATmega8 인공호흡!  (0) 2013.12.27
ATmega128 + LC1628 제어하기 3  (2) 2013.12.25
ATmega128 + LC1628 제어하기 1  (0) 2013.12.24
lc1628 예제 소스  (0) 2013.12.20
Atmega8 으앙 쥬금!!! ㅠㅠ  (0) 2013.12.20
Posted by 구차니
embeded/AVR (ATmega,ATtiny)2013. 12. 24. 23:46
현재는 DDRAM에 문자만 넣는 정도로 간략하게 출력하는 예제이다.

PORTC 에
7654(DATA) 2(E) 1(RW) 0(RS) 로 회로가 구성된 경우의 소스이다.

일단 LC1628의 타이밍 차트는 아래와 같으며
RS/RW 가 동시에 움직이고
E의 falling edge에서 Data를 읽어 가도록 되어있다.



8bit도 해봐야 하는데.. 회로 구성이 일단 4bit로 되어있으니
4비트 강제 설정을 해주어야 하는데
문서의 실수인지 Function Set이 12 비트이다..
그냥 무시하고 8바이트로 보내도 문제는 없는 것 같긴하다.


기본 설정시의 DDRAM 주소이다.
0x40을 더해주면 2번째 라인으로 이동된다.


'embeded > AVR (ATmega,ATtiny)' 카테고리의 다른 글

ATmega128 + LC1628 제어하기 3  (2) 2013.12.25
ATmega128 + LC1628 제어하기 2  (0) 2013.12.24
lc1628 예제 소스  (0) 2013.12.20
Atmega8 으앙 쥬금!!! ㅠㅠ  (0) 2013.12.20
avr pud(pull up disable)  (0) 2013.12.19
Posted by 구차니