학생들이 졸업작품으로 만든 것입니다. 다소 미흡한 점이 많이 있지만
나름 열심히 하여 만든 것입니다.
기타 Sub routine이 필요 하시면 꼬리글 남기시길 바랍니다.....
/*****************************************************
Project : Elevator
Version : 1.0
Date : 2013-11-20
Author :
Company : EU-Technology
Comments:
1. First Drawing : 2013. 11. 10
Chip type : ATmega16
Program type : Application
Clock frequency : 16.000000 MHz
Memory model : Small
External RAM size : 0
Data Stack size : 256
*****************************************************/
#include <mega16.h>
#include <stdio.h>
#include "ElevatorCtl.h"
#include "ElevatorCtl_sub.c"
#include "KeyCheck.c"
#include "SerialCtl.c"
/*==========================================
// External Interrupt 0 service routine
============================================*/
#pragma savereg-
interrupt [EXT_INT0] void ext_int0_isr(void)
{
// Place your code here
}
#pragma savereg+
/*==========================================================
// USART0 (LCD Module) Receiver interrupt service routine
============================================================*/
//===== USART0 Receiver interrupt service routine
#pragma savereg-
interrupt [USART_RXC] void uart_rx_isr(void)
{
char status,data;
#asm
push r26
push r27
push r28
push r29
push r30
push r31
in r26,sreg
push r26
#endasm
status = UCSRA;
data = UDR;
if ((status & (FRAMING_ERROR | PARITY_ERROR | DATA_OVERRUN))==0){
if((RX_Counter >= RX_Buffer_Size) & (data == startdata)) RX_Counter=0;
if(RX_Counter < RX_Buffer_Size){
RX_Buffer[RX_Counter] = data;
if(++RX_Counter >= RX_Buffer_Size) RX_CompFlag = 1;
}
}
#asm
pop r26
out sreg,r26
pop r31
pop r30
pop r29
pop r28
pop r27
pop r26
#endasm
}
#pragma savereg+
//===== USART0 Transmitter interrupt service routine
#pragma savereg-
interrupt [USART_TXC] void uart_tx_isr(void)
{
if(++TX_Counter < TX_Buffer_Size){
UDR = TX_Buffer[TX_Counter];
UCSRB |= TX_ENABLE;
}
else TX_OverFlag = 1;
}
#pragma savereg+
/*==========================================================
// Timer 0 overflow interrupt service routine
============================================================*/
interrupt [TIM0_OVF] void timer0_ovf_isr(void)
{
// Timer0 = 100uSec Interrupt
TCNT0 = (0xFF - 33);
if(--mSec1Counter <= 0){
mSec1Counter = 10;
mSec1Flag = 1;
}
}
/*==========================================================
// Timer 1 overflow interrupt service routine
============================================================*/
interrupt [TIM1_OVF] void timer1_ovf_isr(void)
{
// Place your code here
TCNT1 = (0xFFFF - 32); // 2KHZ
}
/*==========================================================
// Timer 2 overflow interrupt service routine
============================================================*/
interrupt [TIM2_OVF] void timer2_ovf_isr(void)
{
// Place your code here
TCNT2 = (0xFF - 0x100);
}
#include <delay.h>
#define ADC_VREF_TYPE 0x40
/*==========================================================
// ADC interrupt service routine
============================================================*/
interrupt [ADC_INT] void adc_isr(void)
{
unsigned int adc_data;
// Read the AD conversion result
adc_data=ADCW;
// Place your code here
}
/*==========================================================
// Declare your global variables here
============================================================*/
void main(void)
{
// Declare your local variables here
// Input/Output Ports initialization
// Port A initialization
PORTA=0x00;
DDRA=0x00;
// Port B initialization
PORTB=0x00;
DDRB=0xF8;
// Port C initialization
PORTC=0x00;
DDRC=0xFF;
// Port D initialization
PORTD=0x00;
DDRD=0xF2;
// Timer/Counter 0 initialization
TCCR0=0x03; // Clock source: System Clock, Clock value: 250.000 kHz
TCNT0=0xFF; // Mode: Normal top=FFh
OCR0=0x00; // OC0 output: Disconnected
// Timer/Counter 1 initialization
TCCR1A=0x00;
TCCR1B=0x44; // Clock value: 62.500 kHz
// Clock source: System Clock
// OC1A output: Discon.
// OC1B output: Discon.
// Noise Canceler: Off
// Input Capture on Rising Edge
// Timer 1 Overflow Interrupt: on
//TCNT1 = (0xFFFF - 8); // 2KHZ
TCNT1H=0x00; // Mode: Normal top=FFFFh
TCNT1L=0x02;
ICR1H=0x00; // Input Capture Interrupt: Off
ICR1L=0x00;
OCR1AH=0x00; // Compare A Match Interrupt: Off
OCR1AL=0x00;
OCR1BH=0x00; // Compare B Match Interrupt: Off
OCR1BL=0x00;
// Timer/Counter 2 initialization
ASSR=0x00; // Clock source: System Clock
TCCR2=0x07; // Clock value: 15.625 kHz
TCNT2=0x03; // Mode: Normal top=FFh
OCR2=0x00; // OC2 output: Disconnected
// External Interrupt(s) initialization
MCUCR=0x00;
MCUCSR=0x00; // INT0: Off, INT1: Off, INT2: Off
// Timer(s)/Counter(s) Interrupt(s) initialization
TIMSK=0x45;
// USART initialization
// Communication Parameters: 8 Data, 1 Stop, No Parity
UCSRA = 0x00;
UCSRB = 0xD8; // bit7:Rx Interrupt=On, bit6:Tx Interrupt=On,
UCSRC = 0x86; // bit6(0=Asynchronous, 1 =Syncronous)
UBRRH = 0x00;
UBRRL = bps19200; // USART Baud Rate: 19200
// Analog Comparator initialization
ACSR=0x80; // Analog Comparator: Off
SFIOR=0x00; // Analog Comparator Input Capture by Timer/Counter 1: Off
// ADC initialization
ADMUX = ADC_VREF_TYPE & 0xff; // ADC Auto Trigger Source: None
ADCSRA=0x8C; // ADC Voltage Reference: AVCC pin
// ADC Clock frequency: 1000.000 kHz
DataInitial(); // All data initial routine
// Global enable interrupts
#asm("sei")
while(1){
if(mSec1Flag){
mSec1Flag = 0;
if(BuzFlag) BuzTimeCtl(); // Buzzer control Routine
if(BuzOnFlag) BuzOut =1; // Piezzo Buzzer control
else BuzOut = 0;
// Place your code here
KeyScan(); // Key scan Routine
HC595_Disp(); // Flower FND display(74HC595)
FlowerSensor(); // Flower Sensor check routine
}
// DCMotor Control Routine
if(DC_Motor1RunFlag | DC_Motor2RunFlag) DC_MotorCtl();
else {
PORTC &= dc_motor_off; // DC-Motor1 off
PORTD &= dc_motor_off; // DC-Motor2 off
}
// Serial data Control Routine
if(USART_SendFlag) TX_Start();
if(RX_CompFlag) RX_Complete();
};
}
'Project' 카테고리의 다른 글
방사능 피폭 검출기 (0) | 2018.05.07 |
---|---|
Injector Tester (0) | 2015.04.21 |
엘레베이터 콘트롤 회로도..(Main & Key Metrix) (0) | 2013.11.07 |
엘레베이터 모형 기본틀... (0) | 2013.10.08 |