Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
КП записка.doc
Скачиваний:
1
Добавлен:
01.05.2025
Размер:
313 Кб
Скачать
☆

Список использованных источников

  1. Иоффе, В. Г. Методические указания к курсовому проектированию по дисциплине «Микропроцессорные средства систем автоматизации» [Текст]/ В. Г. Иоффе. – Самара: Издательство СГАУ, 2012. – 21с.

  2. Характеристики ATMega16 [Электронный ресурс] – http://microchipinf.com/articles/45/141

  3. ATMega16 Datasheet [Электронный ресурс] – http://downloads.labcenter.co.uk/

  4. Ввод информации с клавиатуры [Электронный ресурс] – http://ofap.ulstu.ru/res/REFER_BOOK_MK48&MK51/keybrd.htm

Приложение а

Принципиальная схема представлена на рисунке 13.

Рисунок 13 – Принципиальная схема МПУ

Приложение б

Спецификация элементов приведена в таблице 2.

Таблица 2 – Спецификация элементов

Номер микросхемы

Тип

Количество

Описание

U1

ATMega16

1

Однокристальный микроконтроллер

U2

7407

4

Диод

U3

MAX487

1

Преобразователь ТТЛ-уровней в дифференциальные сигналы

DI

7SEGM-MPX8-CA-BLUE

1

Цифровой индикатор

R1, R2

2

Резистор

C1

1

Конденсатор

Приложение в

Листинг программы

#include <avr/io.h>

#include <avr/interrupt.h>

#include <avr/sleep.h>

#include <util/delay.h>

#define ind0 0x3F //константы для индикатора

#define ind1 0x06

#define ind2 0x5B

#define ind3 0x4F

#define ind4 0x66

#define ind5 0x6D

#define ind6 0x7D

#define ind7 0x07

#define ind8 0x7F

#define ind9 0x6F

#define line1 0xFE //константы для клавиатуры

#define line2 0xFD

#define line3 0xFB

#define line4 0xF7

#define key1 0xEE

#define key2 0xDE

#define key3 0xBE

#define key4 0xED

#define key5 0xDD

#define key6 0xBD

#define key7 0xEB

#define key8 0xDB

#define key9 0xBB

#define key10 0xE7

#define key11 0xD7

#define key12 0xB7

#define enterKey 10

#define startKey 12

// размер листа, количество листов, общая длина, состояние процесса

int size, amount, length, isOn;

// обработчик прерывания INT0

ISR(INT0_vect)

{

while (!(UCSRA & (1<<UDRE)));

UDR = isOn;

}

int main()

{

size = 0;

amount = 0;

isOn = 0;

// Declare your local variables here

// Input/Output Ports initialization

// Port A initialization

// Func7=Out Func6=Out Func5=Out Func4=Out Func3=Out Func2=Out Func1=Out Func0=Out

// State7=0 State6=0 State5=0 State4=0 State3=0 State2=0 State1=0 State0=0

PORTA=0x00;

DDRA=0xFF;

// Port B initialization

// Func7=Out Func6=Out Func5=Out Func4=Out Func3=Out Func2=Out Func1=Out Func0=Out

// State7=0 State6=0 State5=0 State4=0 State3=0 State2=0 State1=0 State0=0

PORTB=0x00;

DDRB=0xFF;

// Port C initialization

// Func7=In Func6=In Func5=In Func4=In Func3=Out Func2=Out Func1=Out Func0=Out

// State7=T State6=T State5=T State4=T State3=0 State2=0 State1=0 State0=0

PORTC=0x00;

DDRC=0x0F;

// Port D initialization

// Func7=Out Func6=Out Func5=In Func4=Out Func3=Out Func2=In Func1=Out Func0=In

// State7=0 State6=0 State5=P State4=0 State3=0 State2=T State1=0 State0=T

PORTD=0x20;

DDRD=0xDA;

// Timer/Counter 0 initialization

// Clock source: System Clock

// Clock value: Timer 0 Stopped

// Mode: Normal top=FFh

// OC0 output: Disconnected

TCCR0=0x00;

TCNT0=0x00;

OCR0=0x00;

// Timer/Counter 1 initialization

// Clock source: System Clock

// Clock value: Timer 1 Stopped

// Mode: Normal top=FFFFh

// OC1A output: Discon.

// OC1B output: Discon.

// Noise Canceler: Off

// Input Capture on Falling Edge

// Timer 1 Overflow Interrupt: Off

// Input Capture Interrupt: Off

// Compare A Match Interrupt: Off

// Compare B Match Interrupt: Off

TCCR1A=0x00;

TCCR1B=0x00;

TCNT1H=0x00;

TCNT1L=0x00;

ICR1H=0x00;

ICR1L=0x00;

OCR1AH=0x00;

OCR1AL=0x00;

OCR1BH=0x00;

OCR1BL=0x00;

// Timer/Counter 2 initialization

// Clock source: System Clock

// Clock value: Timer 2 Stopped

// Mode: Normal top=FFh

// OC2 output: Disconnected

ASSR=0x00;

TCCR2=0x00;

TCNT2=0x00;

OCR2=0x00;

// External Interrupt(s) initialization

// INT0: On

// INT0 Mode: Falling Edge

// INT1: Off

// INT2: Off

GICR|=0x40;

MCUCR=0x02;

MCUCSR=0x00;

GIFR=0x40;

// Timer(s)/Counter(s) Interrupt(s) initialization

TIMSK=0x00;

// USART initialization

// Communication Parameters: 8 Data, 1 Stop, No Parity

// USART Receiver: Off

// USART Transmitter: On

// USART Mode: Asynchronous

// USART Baud rate: 9600

UBRRH=0x00;

UBRRL=0x33;

UCSRB=0x08;

UCSRC=0x86;

// Analog Comparator initialization

// Analog Comparator: Off

// Analog Comparator Input Capture by Timer/Counter 1: Off

ACSR=0x80;

SFIOR=0x00;

// Global enable interrupts

sei();

//My own code

input();

while (getKey() != startKey) {}

process();

while (1) {

showAll();

}

return 0;

}

void process() {

// импульс запуска

PORTD = PIND | 0x10;

_delay_ms(3);

PORTD = PIND & 0xEF;

for (int a = 0; a < amount; a++) {

char wasLowered = 0;

isOn = 1;

for (int s = size * 1000; s > 0; s--) {

if (s < 500 && wasLowered == 0) {

// импульс замедления протяжки

PORTD = PIND | 0x40;

_delay_ms(3);

PORTD = PIND & 0xBF;

wasLowered = 1;

isOn = 2;

}

// ожидание импульса протяжки

while (PIND & 0x20 == 0) {

showAll();

}

showAll();

}

// конец листа

PORTD = PIND | 0x08;

_delay_ms(3);

PORTD = PIND & 0xF7;

}

isOn = 0;

// окончание раскроя

PORTD = PIND | 0x80;

showAll();

// 1 for showAll() + 2 = 3

_delay_ms(2);

PORTD = PIND & 0x7F;

}

void input() {

int k1, k2, k3;

// ввод размера листа

k1 = getKey();

if (k1 == 0) {k1 = 1;}

k2 = getKey();

if (k2 == enterKey) {

size = k1;

} else {

while (getKey() != enterKey) {}

size = 10;

}

// ввод количества листов

k1 = getKey();

if (k1 == 0) {k1 = 1;}

k2 = getKey();

if (k2 == enterKey) {

amount = k1;

} else {

while (getKey() != enterKey) {}

if (k1 >= 5) {

amount = 50;

} else {

amount = k1 * 10 + k2;

}

}

length = size * amount;

}

// функция, считывающая код следующей клавиши с клавиатуры

int getKey() {

while(1)

{

// first line

m1: showAll();

PORTC = line1;

switch(PINC) {

case line1:

PORTC = line2;

switch(PINC) {

case line2:

PORTC = line3;

switch(PINC) {

case line3:

PORTC = line4;

switch(PINC) {

case line4:

goto m1;

case key10:

while (PINC != line4) {_delay_us(50);}

return enterKey;

case key11:

while (PINC != line4) {_delay_us(50);}

return 0;

case key12:

while (PINC != line4) {_delay_us(50);}

return startKey;

}

case key7:

while (PINC != line3) {_delay_us(50);}

return 7;

case key8:

while (PINC != line3) {_delay_us(50);}

return 8;

case key9:

while (PINC != line3) {_delay_us(50);}

return 9;

}

case key4:

while (PINC != line2) {_delay_us(50);}

return 4;

case key5:

while (PINC != line2) {_delay_us(50);}

return 5;

case key6:

while (PINC != line2) {_delay_us(50);}

return 6;

}

case key1:

while (PINC != line1) {_delay_us(50);}

return 1;

case key2:

while (PINC != line1) {_delay_us(50);}

return 2;

case key3:

while (PINC != line1) {_delay_us(50);}

return 3;

}

}

}

// отображение заданной цифры в заданной позиции индикатора

void show(int digit, int pos) {

switch(pos) {

case 1:

PORTB = 0x01; break;

case 2:

PORTB = 0x02; break;

case 3:

PORTB = 0x04; break;

case 4:

PORTB = 0x08; break;

case 5:

PORTB = 0x10; break;

case 6:

PORTB = 0x20; break;

case 7:

PORTB = 0x40; break;

case 8:

PORTB = 0x80; break;

}

switch(digit) {

case 0:

PORTA = ind0; break;

case 1:

PORTA = ind1; break;

case 2:

PORTA = ind2; break;

case 3:

PORTA = ind3; break;

case 4:

PORTA = ind4; break;

case 5:

PORTA = ind5; break;

case 6:

PORTA = ind6; break;

case 7:

PORTA = ind7; break;

case 8:

PORTA = ind8; break;

case 9:

PORTA = ind9; break;

}

_delay_ms(1);

}

// отображение размера листа

void showSize() {

show((size % 100) / 10, 1);

show(size % 10, 2);

}

// отображение количества листов

void showAmount() {

show((amount % 100) / 10, 4);

show(amount % 10, 5);

}

// отображение состояния технологического процесса

void showWorking() {

show(isOn, 7);

}

// отображение индицируемой информации

void showAll() {

showSize();

showAmount();

showWorking();

}