Micom_Electric/마이컴_원칩 2011. 5. 22. 17:35

현재까지 작업된 것
99% 프로그램 사이즈 - 추가 코딩 여유없슴
다른 모듈에서 사용할 변수는 헤더화일에서 변수 정의 / 선언만 하고
초기화는 메인 등에서 실시.
PROMEM 형식은 프로그램 에 데이터 저장...  

//------------------------------------------------------------------------------
// FastPWM mode is possible only 8bit timer/counter2 & 16bit T/C
// in 8bit T/C2 mode - Output pin = PB4 OC2 (MISO), duty = OCR2
// the Output Compare (OC2) is cleared on the Compare
// Match between TCNT2 and OCR2, and set at BOTTOM
// DDRB=0x08;
// PORTB=0x08;
// TCCR2=0b01101100 (FastPWM, COM21,COM20=[1 0];
// OCR2 = 0 ; duty = 0%
// in 16bit timer/counter mode - Output pin = PB1 OC1A, duty = OCR1A
// Use this mode in order to use PB1 as PB4 is assigned to SD card
void SetupFastPWM(void){
// PWM Hz = clk/[N*(1+TOP)] = 8000000/[1*(1+255)] = 31,250 Hz
DDRB  |= 0x02; //Set PB1/OC1A as an output. Drives a low by default.
PORTB |= 0x02;
// (COM1A[10]:out chan=A, WGM1310[0101]:FastPWM 8Bit)
// TCCR1A = COM1A1 COM1A0 COM1B1 COM1B0 FOC1A FOC1B WGM11 WGM10
TCCR1A = 0b10000001; // (COM1A=10 for OCR1A out pin, WGM11.10=01)
// TCCR1B = ICNC1 ICES1 - WGM13 WGM12 CS12 CS11 CS10
TCCR1B = 0b00000001; // (WGM13.12=00, prescale=1)
OCR1A = 125;   // Default duty = 50%
}
====================================================== 
 // ----------------------------------------------------------------------------------
void LCD2FloatXYn_m(uint8_t x, uint8_t y, float data, uint8_t n, uint8_t m){
// when using dtostrf : n=total width, m=below zero

   char LCDtext[] = "        ";

dtostrf(data, 8, 2, LCDtext);
LCDputsXY(x, y, LCDtext);
}
// -------------------------------------------------------------------------------
/*
22.10.4.10 char dtostrf (double val, signed char_width, unsigned char __-
prec, char s)
The dtostrf() function converts the double value passed in val into an ASCII
representationthat will be stored under s. The caller is responsible for
providing sufficient storage in s.
Conversion is done in the format "[-]d.ddd". The minimum field width of the
output string (including the ’.’ and the possible sign for negative values)
 is given in width, and prec determines the number of digits after the decimal
sign. width is signed value, negative for left adjustment.
The dtostrf() function returns the pointer to the converted string s.
*/
=================================================================================
 
posted by 털보네i
: