Главная  Микроконтроллеры 

[0] [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14] [15] [16] [17] [18] [19] [20] [21] [22] [23] [24] [25] [26] [27] [28] [29] [30] [31] [32] [33] [34] [35] [36] [37] [38] [39] [40] [41] [ 42 ] [43] [44] [45] [46] [47] [48] [49] [50] [51] [52] [53] [54] [55] [56] [57] [58] [59] [60] [61] [62] [63] [64] [65] [66] [67] [68] [69] [70] [71] [72] [73] [74] [75] [76] [77] [78] [79] [80] [81] [82] [83] [84] [85] [86] [87] [88] [89] [90] [91] [92] [93]

void display(unsigned int N, unsigned int N1, unsigned int N2) { NN N1N1N1N1 N2N2N2N2

Set Bus(0);

STROB ADR();

out((unsigned int)(N/10)-10.(unsigned int)(N/100)); out(N-10(unsigned int)(N/10));

out((unsigned int)(N1/1000)-10*(unsigned int)(N1/10000)); out((unsigned int)(N1/100)-10.(unsigned int)(N1/1000)); out((unsigned int)(N1/10)-10-(unslgned int)(N1/100)); out(N1-10.(unsigned int)(N1/10));

out((unsigned int)(N2/1000)-10«(unsigned int)(N2/10000)); out((unsigned int)(N2/100)-10*(unsigned int)(N2/1000)); out((unsigned int)(N2/10)-10.(unsigned int)(N2/100)); out(N2-10(unsigned int)(N2/10));

>

((include <io8535.h> void tnainO

DDRB = OxFF; /* Port С настроен на вывод «/

PORTB = Oxff; /« Все линии порта С = 1 «/

Init LCD();

display(0,1,7);

while(l);

>

Динамическая индикация

Динамическая индикация с применением прерывания по переполнению таймера Timer 0. Вывод на индикатор происходит каждые 65 мс. Прерывания по таймеру 1 происходят с периодом примерно 1 с. При этом на единицу увеличивается значение на индикаторе. При достижении значения 20 происходит обнуление значения для вывода.

Микроконтроллер: AT90S2313.

Кварцевый резонатор: 4 МГц.

Текст программы:

((include <90s2313.h> ((include "HG.h"

Timer 0 overflow interrupt service routine interrupt [TIM0 0VF] void timerO ovf isr(void) {

Reinitialize Timers 0 value



TCNTO=OxFF:

Place your code here

HG12():

>

Timer 1 overflow Interrupt service routine interrupt [TIM1 0VF] void timer1 ovf isr(void) (

Reinitialize Timers 1 value

TCNT1H=OxfO;

TCNT1L=0)(be;

Place your code here

N++;

if (N==20) N=0; >

Declare your global variables here

void main(void) (

unsigned int temp,tempi,tetnp2;

Input/Output Ports initialization

Port В

P0RTB=0x00;

pDRB=OxFF;

Port D

P0RTD=0x00;

DDRD=0x00;

Timer/Counter 0 initialization

Clock source: System Clock

Clock value: 3906 kHz

Mode: Output Compare

OCD output: Disconnected

TCCR0=0x05:

TCNT0=0xFF;

Timer/Counter 1 initialization

Clock source: System Clock

Clock value: 3,906 kHz

Mode: Output Compare

0C1 output: Discon.

Noise Canceler: Off

Input Capture on Falling Edge

TCCR1A=OxOO;

TCCR1B=0x05:

TCNT1H=OxfO;

TCNT1L=0xbe;

OCR1H=OxOO;

0CR1L=0xn;



II External Interrupt(s) initialization

INTO: Off

INT1: Off

GIMSK=0x00;

HCUCR=0x00:

Timer(s)/Counter(s) Interrupt(s) initialization TIMSK=0x82;

Analog Comparator initialization Analog Comparator: Off

Analog Comparator Input Capture by Timer/Counter 1: Off ACSR=0x80.

Global enable interrupts «asm("sei")

init HG();

N=0;

while (1) {

>:

>

Звуковой генератор на частоту 1000 Гц

К нулевой линии порта В подсоединен транзисторный ключ, управляющий динамической головкой. Микроконтроллер: AT90S2313. Кварцевый резонатор: 4 МГц.

((include <90s2313.h>

Процедура обработки прерывания Timer 1 по переполнению

interrupt [TIM1 0VF] void timer1 ovf isr(void)

Перезагрузить значение Timer 1

TCNT1H=0xff;

TCNTlL=0xfd;

if (PINB.O==0) PORTB.0=1; else PORTB.0=0; >

void main(void) {

Инициализация портов ввода/вывода

Port В

DDRB=OxFF;

PORTB=OxOO;

Port D



[0] [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14] [15] [16] [17] [18] [19] [20] [21] [22] [23] [24] [25] [26] [27] [28] [29] [30] [31] [32] [33] [34] [35] [36] [37] [38] [39] [40] [41] [ 42 ] [43] [44] [45] [46] [47] [48] [49] [50] [51] [52] [53] [54] [55] [56] [57] [58] [59] [60] [61] [62] [63] [64] [65] [66] [67] [68] [69] [70] [71] [72] [73] [74] [75] [76] [77] [78] [79] [80] [81] [82] [83] [84] [85] [86] [87] [88] [89] [90] [91] [92] [93]

0.0008