BASIC4MCU | 질문게시판 | 답변 : atmega128 PC PWM 파형출력 도와주세요 ㅠ
페이지 정보
작성자 master 작성일2019-11-11 11:28 조회4,662회 댓글1건
https://www.basic4mcu.com/bbs/board.php?bo_table=gac&wr_id=10660
본문
우선 타이머2로 3초를 만드세요
TCCR2=0x0B; OCR2=249; TIMSK=0x80; //16000000/64/(1+249),1ms
#pragma interrupt_handler timer0_comp_isr:iv_TIM2_COMPvoid timer2_comp_isr(void){ // 1msif(++cnt>=3000){ cnt=0; // 1ms*3000=3sec// 여기서 OCR값을 변경합니다.}}
// MCU BASIC: https://www.basic4mcu.com// DateTime : 2019-11-11 오전 11:32:50// by Ok-Hyun Park//#include <iom128v.h>#include <stdio.h>#include "lcd.h"//volatile unsigned int cnt=0;volatile unsigned char mode=0,flag=1;//#pragma interrupt_handler timer0_comp_isr: iv_TIM2_COMPvoid timer2_comp_isr(void){ // 1msif(++cnt>=3000){ cnt=0; // 1ms*3000=3secif(++mode>4)mode=0;switch(mode){case 0: OCR0= 0; break;case 1: OCR0= 63; break;case 2: OCR0=127; break;case 3: OCR0=191; break;case 4: OCR0=255; break;}flag=1;}}//void main(void){char str[30];//DDRB=0xff;PortInit();LCD_Init();//TCCR0=(1<<WGM00)|(1<<COM00)|(1<<CS01)|(1<<CS00); OCR0=0; // fpwm=0.98khz인 32분주비,비반전모드TCCR2=0x0B; OCR2=249; TIMSK=0x80; //16000000/64/(1+249),1msSREG|=0x80;while(1){if(flag){ flag=0;sprintf(str,"03d%%",mode*25);LCD_pos(0,0); LCD_STR(str);}}}
댓글 1
조회수 4,662jjw332님의 댓글
jjw332 작성일항상 감사합니다 도움이 많이되었습니다 ^^