본문 바로가기
코스웨어/13년 스마트컨트롤러

[AVR 보고서용 main소스입니다] by. 남경

by 알 수 없는 사용자 2013. 6. 11.
728x90
반응형


사용법은 간단합니다. 살리고 싶은 챕터로 가서


/************************************************************************************************

***********************3. T/C와 인터럽트 레지 제어하여 LED 1초간격 깜빡이기    ********************

*************************************************************************************************/

빨간색으로 표시한 /만 넣으시면 소스가 살아납니다. 죽이고 싶으면 다시 /를 넣으면 됩니다.







/************************************************************************************************

********************************      목                 차      ********************************

*************************************************************************************************


1. PORT A 활용하여 LED 불 켜기

2. UART사용하여 하이퍼터미널에 Hi, Hello!! 띄우기

3. T/C와 인터럽트 레지 제어하여 LED 1초간격 깜빡이기

4. UART와 인터럽트 레지 제어로 PORTA에 부착된 LED 점등시키기

5. T/C와 인터럽트 레지 제어하여 LCD에 딜레이 적용하기

6. ADC레지 제어하여 조도, 온도센서 값 컨버팅 하기

7. UART와 인터럽트 레지 제어로 PORTA에 부착된 LED 점등시키기

8. EEPROM에 읽고 쓰기

9. 인터럽트 활용하여 LCD에 글씨 띄우기

10 . 초음파센서 구동하기


/************************************************************************************************/


/************************************************************************************************

******************************   1. PORT A 활용하여 LED 불 켜기   *******************************

*************************************************************************************************

#define PORTA (*((volatile unsigned char *)0x22)) 

#define DDRA (*((volatile unsigned char *)0x21)) // Port A Data Direction Register

#define PINA (*((volatile unsigned char *)0x20)) // Port A Input Pins Address


int main()

{

volatile unsigned int ui_Cnt1;

volatile unsigned int ui_Cnt2;


DDRA = 0xff; //출력 방향 설정 : 1=출력 0=입력(CPU 기준), ARM에선 CODR과 SODR

PORTA = 0xff;

while(1)

{

for(ui_Cnt1=0 ; ui_Cnt1 < 10000; ++ui_Cnt1)

for(ui_Cnt2=0 ; ui_Cnt2 < 100; ++ui_Cnt2); //1000000까지 한번에 셀 수 없기 때문에...

PORTA = 0;

for(ui_Cnt1=0 ; ui_Cnt1 < 10000; ++ui_Cnt1)

for(ui_Cnt2=0 ; ui_Cnt2 < 100; ++ui_Cnt2); //1000000까지 한번에 셀 수 없기 때문에...

PORTA = 0xff;

}


return 0;

}


/************************************************************************************************/




/************************************************************************************************

*********************** 2. UART사용하여 하이퍼터미널에 Hi, Hello!! 띄우기 ***********************

*************************************************************************************************


#include "lcd.h"

#include "timer.h"

#include "uart.h"

#include "adc.h"


int main(void)

{

UART_Init();

LCD_Init();

UART_Send_String("Hi, Hello!!");


while(1);


return 0;

}

/************************************************************************************************/



/************************************************************************************************

********************** 3. T/C와 인터럽트 레지 제어하여 LED 1초간격 깜빡이기 *********************

*************************************************************************************************


#include "lcd.h"

#include "timer.h"

#include "uart.h"

#include "adc.h"



int main(void)

{

UART_Init();

LCD_Init();

while(1)

{

sleep(); // CPU를 기절시키는 명령, 즉, 최소한으로 가동하게(인터럽트만 살아있네~)

}

Timer0_Init();

LCD_Run();

DDRA = 0xff; //출력 방향 설정 : 1=출력 0=입력(CPU 기준)

PORTA = 0xff;

while(1)

{

ms_Delay(1000);

PORTA = 0;

ms_Delay(1000);

PORTA = 0xff;

}


while(1);


return 0;

}


/************************************************************************************************/



/************************************************************************************************

****************** 4. UART와 인터럽트 레지 제어로 PORTA에 부착된 LED 점등시키기 *****************

*************************************************************************************************


#include "lcd.h"

#include "timer.h"

#include "uart.h"

#include "adc.h"


int main(void)

{

UART_Init();

while(1)

{

sleep(); // CPU를 기절시키는 명령, 즉, 최소한으로 가동하게(인터럽트만 살아있네~)

}


return 0;

}


/************************************************************************************************/



/************************************************************************************************

********************* 5. T/C와 인터럽트 레지 제어하여 LCD에 딜레이 적용하기  ********************

*************************************************************************************************


#include "lcd.h"

#include "timer.h"

#include "uart.h"

#include "adc.h"


int main(void)

{

LCD_Init();

Timer0_Init();

LCD_Run();


while(1);


return 0;

}


/************************************************************************************************/




/************************************************************************************************

*********************** 6. ADC레지 제어하여 조도, 온도센서 값 컨버팅 하기 ***********************

*************************************************************************************************


#include "lcd.h"

#include "timer.h"

#include "uart.h"

#include "adc.h"


int main(void)

{

LCD_Init();

while(1)

{

LCD_number(1, Sensor_Light());

LCD_number(2, Sensor_Temp());

}


return 0;

}


/************************************************************************************************/


/************************************************************************************************

****************** 7. UART와 인터럽트 레지 제어로 PORTA에 부착된 LED 점등시키기 *****************

*************************************************************************************************

#include "lcd.h"

#include "timer.h"

#include "uart.h"

#include "adc.h"


int main(void)

{

UART_Init_Recv();

LCD_Init();


LCD_STRING(UART_Recv_String());

while(1);

return 0;

}


/************************************************************************************************/



/************************************************************************************************

*********************************** 8. EEPROM에 읽고 쓰기 ***************************************

*************************************************************************************************


#include "lcd.h"

#include "timer.h"

#include "uart.h"

#include "adc.h"

#include "eep.h"


int main(void)

{

LCD_Init();


EepRom_Write(0xFFF, 'A');

LCD_DATA_Write(EepRom_Read(0xFFF));


while(1);

}


/************************************************************************************************/


/************************************************************************************************

**************************** 9. 인터럽트 활용하여 LCD에 글씨 띄우기 *****************************

*************************************************************************************************


#include "lcd.h"

#include "timer.h"

#include "uart.h"

#include "adc.h"

#include "eep.h"

#include "ext_int.h"


int main(void)

{

LCD_Init();

INT_Init();

while(1)

{

sleep(); // CPU를 기절시키는 명령, 즉, 최소한으로 가동하게(인터럽트만 살아있네~)

}


while(1);


return 0;

}


/************************************************************************************************/



/************************************************************************************************

*********************************** 10 . 초음파센서 구동하기 ************************************

*************************************************************************************************/

#include "lcd.h"

#include "ultra.h"


int main(void)

{

volatile unsigned int iCnt;

volatile unsigned int iCnt2;


LCD_Init();

Ultra_Init();

while(1)

{

for(iCnt = 0; iCnt < 1000; ++iCnt)

for(iCnt2 = 0; iCnt2 < 50; ++iCnt2);

LCD_CMD_Write(0x80);

LCD_STRING(ULTRA_Run());

}

while(1);

}


/************************************************************************************************/


728x90