Romikgy писал(а):
выложили бы весь проект ...
только почему то вместо русских букв абра кодабра
Код:
/*****************************************************
This program was produced by the
CodeWizardAVR V1.25.8 Standard
Automatic Program Generator
© Copyright 1998-2007 Pavel Haiduc, HP InfoTech s.r.l.
http://www.hpinfotech.com
Project :
Version :
Date : 18.12.2017
Author : F4CG
Company : F4CG
Comments:
Chip type : ATmega2560
Program type : Application
Clock frequency : 16,000000 MHz
Memory model : Small
External SRAM size : 0
Data Stack size : 2048
*****************************************************/
// Äèñïëåé íà ïîðò À
// êíîïêè íà ïîðò C C0 C2 C4 C8
// êíîïêà ïðîêðóòêè + íà C
// êíîïêà ïðîåðóòêè - íà C
#include <mega2560.h>
// Alphanumeric LCD Module functions
#asm
.equ __lcd_port=0x02 ;PORTA
#endasm
#include <lcd.h>
#include <stdio.h>
#include <delay.h>
#define ADC_VREF_TYPE 0x00
unsigned int index;
char a[512]; // ìàññèâ èç 512 ïåðåìååíûõ êóäà ïèøåì çíà÷åíèÿ êàíàëà
char x[512]; // ìàññèâ èç 512 ïåðåìååíûõ êóäà ïèøåì íîìåð êàíàäà
unsigned char b; //
unsigned char b1; //
unsigned char b2; //
unsigned char b3; //
unsigned int n_in_massiv; // íîìåð â ìàññèâå "à" - çíà÷åíèå êàíàëà
unsigned int n_in_massiv_x; // íîìåð â ìàññèâå õ íîìåð êàíàëà
unsigned char string[4]; // ìàññèâ èç 3õ ïåðåìåííûõ äëÿ âûâîäà ñòðîêè
unsigned char kn1; // ñ÷åò÷èê êíîïêè 1 ïðîêðóòêà +
unsigned char kn2; // ñ÷åò÷èê êíîïêè 2 ïðîêðóòêà -
unsigned char kn3; // ñ÷åò÷èê êíîïêè 3 äàííûå
unsigned char kn4; // ñ÷åò÷èê êíîïêè 3 äàííûå -
unsigned char kn5; // ñ÷åò÷èê êíîïêè 3 äàííûå -
// Read the AD conversion result
unsigned int read_adc(unsigned char adc_input)
{
ADMUX=(adc_input & 0x07) | (ADC_VREF_TYPE & 0xff);
if (adc_input & 0x08) ADCSRB |= 0x08;
else ADCSRB &= 0xf7;
// Delay needed for the stabilization of the ADC input voltage
delay_us(10);
// Start the AD conversion
ADCSRA|=0x40;
// Wait for the AD conversion to complete
while ((ADCSRA & 0x10)==0);
ADCSRA|=0x10;
return ADCW;
}
// Declare your global variables here
void main(void)
{
// Declare your local variables here
// Crystal Oscillator division factor: 1
#pragma optsize-
CLKPR=0x80;
CLKPR=0x00;
#ifdef _OPTIMIZE_SIZE_
#pragma optsize+
#endif
// 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 èí ñ ïîäòÿæêîé ?
PORTC=0xFF;
DDRC=0x00;
// Port D initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTD=0x00;
DDRD=0x00;
// Port E initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTE=0x00;
DDRE=0x00;
// Port F initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTF=0x00;
DDRF=0x00;
// Port G initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTG=0x00;
DDRG=0x00;
// Port H initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTH=0x00;
DDRH=0x00;
// Port J initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTJ=0x00;
DDRJ=0x00;
// Port K initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTK=0x00;
DDRK=0x00;
// Port L initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTL=0x00;
DDRL=0x00;
// Timer/Counter 0 initialization
// Clock source: System Clock
// Clock value: Timer 0 Stopped
// Mode: Normal top=FFh
// OC0A output: Disconnected
// OC0B output: Disconnected
TCCR0A=0x00;
TCCR0B=0x00;
TCNT0=0x00;
OCR0A=0x00;
OCR0B=0x00;
// Timer/Counter 1 initialization
// Clock source: System Clock
// Clock value: Timer 1 Stopped
// Mode: Normal top=FFFFh
// OC1A output: Discon.
// OC1B output: Discon.
// OC1C 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
// Compare C Match Interrupt: Off
TCCR1A=0x00;
TCCR1B=0x05;
TCNT1H=0x00;
TCNT1L=0x00;
ICR1H=0x00;
ICR1L=0x00;
OCR1AH=0x00;
OCR1AL=0x00;
OCR1BH=0x00;
OCR1BL=0x00;
OCR1CH=0x00;
OCR1CL=0x00;
// Timer/Counter 2 initialization
// Clock source: System Clock
// Clock value: Timer 2 Stopped
// Mode: Normal top=FFh
// OC2A output: Disconnected
// OC2B output: Disconnected
ASSR=0x00;
TCCR2A=0x00;
TCCR2B=0x00;
TCNT2=0x00;
OCR2A=0x00;
OCR2B=0x00;
// Timer/Counter 3 initialization
// Clock source: System Clock
// Clock value: Timer 3 Stopped
// Mode: Normal top=FFFFh
// Noise Canceler: Off
// Input Capture on Falling Edge
// OC3A output: Discon.
// OC3B output: Discon.
// OC3C output: Discon.
// Timer 3 Overflow Interrupt: Off
// Input Capture Interrupt: Off
// Compare A Match Interrupt: Off
// Compare B Match Interrupt: Off
// Compare C Match Interrupt: Off
TCCR3A=0x00;
TCCR3B=0x00;
TCNT3H=0x00;
TCNT3L=0x00;
ICR3H=0x00;
ICR3L=0x00;
OCR3AH=0x00;
OCR3AL=0x00;
OCR3BH=0x00;
OCR3BL=0x00;
OCR3CH=0x00;
OCR3CL=0x00;
// Timer/Counter 4 initialization
// Clock source: System Clock
// Clock value: Timer 4 Stopped
// Mode: Normal top=FFFFh
// OC4A output: Discon.
// OC4B output: Discon.
// OC4C output: Discon.
// Noise Canceler: Off
// Input Capture on Falling Edge
// Timer 4 Overflow Interrupt: Off
// Input Capture Interrupt: Off
// Compare A Match Interrupt: Off
// Compare B Match Interrupt: Off
// Compare C Match Interrupt: Off
TCCR4A=0x00;
TCCR4B=0x00;
TCNT4H=0x00;
TCNT4L=0x00;
ICR4H=0x00;
ICR4L=0x00;
OCR4AH=0x00;
OCR4AL=0x00;
OCR4BH=0x00;
OCR4BL=0x00;
OCR4CH=0x00;
OCR4CL=0x00;
// Timer/Counter 5 initialization
// Clock source: System Clock
// Clock value: Timer 5 Stopped
// Mode: Normal top=FFFFh
// OC5A output: Discon.
// OC5B output: Discon.
// OC5C output: Discon.
// Noise Canceler: Off
// Input Capture on Falling Edge
// Timer 5 Overflow Interrupt: Off
// Input Capture Interrupt: Off
// Compare A Match Interrupt: Off
// Compare B Match Interrupt: Off
// Compare C Match Interrupt: Off
TCCR5A=0x00;
TCCR5B=0x00;
TCNT5H=0x00;
TCNT5L=0x00;
ICR5H=0x00;
ICR5L=0x00;
OCR5AH=0x00;
OCR5AL=0x00;
OCR5BH=0x00;
OCR5BL=0x00;
OCR5CH=0x00;
OCR5CL=0x00;
// External Interrupt(s) initialization
// INT0: Off
// INT1: Off
// INT2: Off
// INT3: Off
// INT4: Off
// INT5: Off
// INT6: Off
// INT7: Off
EICRA=0x00;
EICRB=0x00;
EIMSK=0x00;
// PCINT0 interrupt: Off
// PCINT1 interrupt: Off
// PCINT2 interrupt: Off
// PCINT3 interrupt: Off
// PCINT4 interrupt: Off
// PCINT5 interrupt: Off
// PCINT6 interrupt: Off
// PCINT7 interrupt: Off
// PCINT8 interrupt: Off
// PCINT9 interrupt: Off
// PCINT10 interrupt: Off
// PCINT11 interrupt: Off
// PCINT12 interrupt: Off
// PCINT13 interrupt: Off
// PCINT14 interrupt: Off
// PCINT15 interrupt: Off
// PCINT16 interrupt: Off
// PCINT17 interrupt: Off
// PCINT18 interrupt: Off
// PCINT19 interrupt: Off
// PCINT20 interrupt: Off
// PCINT21 interrupt: Off
// PCINT22 interrupt: Off
// PCINT23 interrupt: Off
PCMSK0=0x00;
PCMSK1=0x00;
PCMSK2=0x00;
PCICR=0x00;
// Timer/Counter 0 Interrupt(s) initialization
TIMSK0=0x00;
// Timer/Counter 1 Interrupt(s) initialization
TIMSK1=0x00;
// Timer/Counter 2 Interrupt(s) initialization
TIMSK2=0x00;
// Timer/Counter 3 Interrupt(s) initialization
TIMSK3=0x00;
// Timer/Counter 4 Interrupt(s) initialization
TIMSK4=0x00;
// Timer/Counter 5 Interrupt(s) initialization
TIMSK5=0x00;
// Analog Comparator initialization
// Analog Comparator: Off
// Analog Comparator Input Capture by Timer/Counter 1: Off
ACSR=0x80;
ADCSRB=0x00;
// ADC initialization
// ADC Clock frequency: 125,000 kHz
// ADC Voltage Reference: AREF pin
// ADC Auto Trigger Source: Free Running
// Digital input buffers on ADC0: On, ADC1: On, ADC2: On, ADC3: On
// ADC4: On, ADC5: On, ADC6: On, ADC7: On
DIDR0=0x00;
// Digital input buffers on ADC8: On, ADC9: On, ADC10: On, ADC11: On
// ADC12: On, ADC13: On, ADC14: On, ADC15: On
DIDR2=0x00;
ADMUX=ADC_VREF_TYPE & 0xff;
ADCSRA=0xA7;
ADCSRB&=0xF8;
// LCD module initialization
lcd_init(16);
lcd_init(16);
//èíèöèàëèçèðóåò èìåííî ÆÊÈ (LCD) ãäå 16 ñèìâîëîâ íà ñòðîêó
//Ìû ìîæåì óêàçàòü â êàêóþ ïîçèöèþ âûâîäèòü ñèìâîë âîò òàê:
// lcd_gotoxy(4,1);
//è âûâîä ñèìâîëîâ íà÷íåòñÿ ñ 5-é ïîçèöèè âî âòîðîé ñòðîêå.
//приветсвтвие
lcd_gotoxy(4,0);
lcd_putsf("DMX-512");
lcd_gotoxy(0,1);
lcd_putsf("hello word");
lcd_putsf("e");
delay_ms(2000); // çàäåðæêà , æäåì
/*
Òåïåðü äàâàéòå ïîçíàêîìèìñÿ ñ ôóíêöèåé, êîòîðàÿ çàíèìàåòñÿ ôîðìàòèðîâàíèåì òåêñòà.
void printf(char flash *fmtstr [,arg1, arg2, ...])
Êàê îíà ðàáîòàåò. Â char flash *fmtstr çàäàåòñÿ ôîðìàò âûâîäèìîãî
çíà÷åíèÿ, à â àðãóìåíòû arg1, arg2, ... èìÿ ïåðåìåííîé.
Ïðèìåð.
unsigned char temp = 123;
printf("temp = %05d\n", temp);
×òî îçíà÷àåò ýòà àáðà-êàäàáðà. Ïåðâàÿ ñòðîêà ñîçäàåò ïåðåìåííóþ è ïðèñâàåâàåò åé
çíà÷åíèå. Òóò âñå ïîíÿòíî, à âîò ÷òî äåëàåò âòîðàÿ. Âñå ïî ïîðÿäêó. Ñíà÷àëà âûâîäèòñÿ
çàïèñü temp = , çàòåì 00123. Ïî÷åìó âûâîäèòñÿ 00123. À ïîòîìó ÷òî ó íàñ åñòü óñëîâèå
%05d\n êîòîðîå ãîâîðèò:
1) % - áóäåì ôîðìàòèðîâàòü çíà÷åíèÿ ïåðâîãî àðãóìåíòà
2) 0 - áóäåì âûâîäèòü n çíàêîâ, ïóñòûå çàáüåì íóëÿìè
3) 5 - âûâîäèì 5 çíàêîâ, åñëè ÷èñëî ìåíüøå 5 çíàêîâ, òî çàïîëíèòü ïóñòûøêè
íóëÿìè. Îá ýòîì ãîâîðèò ïóíêò 2. ×èñëî áóäåò âûðîâíåíî ïî ïðàâîìó êðàþ.
4) d - âûâîäèì ÷èñëî â äåñÿòè÷íîì ôîðìàòå.
5) \n - Çàñòàâèò ïîñëå âûâîäà ñèìâîëà ïåðåéòè íà äðóãóþ ñòðîêó.
Ñëåäóþùàÿ ôóíêöèÿ.
void sprintf(char flash, char flash *fmtstr [,arg1, arg2, ...])
Âîò ýòà ôóíêöèÿ íàì íàèáîëåå èíòåðåñíà. Îíà ôîðìàòèðóåò ñòðîêó è çàïèñûâàåò åå â
ìàññèâ. Ïîñëå ìû ìîæåì ñìåëî ìàññèâ âûâåñòè íà ýêðàí. Êàê îíà ðàáîòàåò.
unsigned char temp = 123;
unsigned char string[20];
sprintf(string, "temp = %05d\n", temp);
lcd_puts(string);
// áëà áëà áëà
lcd_init(LCD_DISP_ON); // Âêëþ÷èòü äèñïëåé áåç êóðñîðà
lcd_init(LCD_DISP_ON_CURSOR); // ñ êóðñîðîì
lcd_clrscr(); // î÷èñòèòü ýêðàí äèñïëåÿ
lcd_home(); // âåðíóòü êóðñîð â íà÷àëî (x=0; y=0)
lcd_puts("hello"); // íàïèñàòü ÷òî íèáóäü
lcd_gotoxy(0,1); // Ïåðåìåñòèòü êóðñîð â êîîðäèíàòó (x=0; y=1)
// Êàê âûâîäèòü öèôðû
char buffer[10];
int n = 12345;
itoa(n, buffer, 10);
lcd_puts(buffer);
// float
char buffer[10];
float f = 3.1415926;
sprintf(buffer, "%f", f);
lcd_puts(buffer);
*/
x[0]=1; // çàäàåì íîìåð êàíàäà
x [ 1 ] = 2 ; //
x [ 2 ] = 3 ;
x [ 3 ] = 4 ;
x [ 4 ] = 5 ;
x [ 5 ] = 6 ;
x [ 6 ] = 7 ;
x [ 7 ] = 8 ;
x [ 8 ] = 9 ;
x [ 9 ] = 10 ;
x [ 10 ] = 11 ;
x [ 11 ] = 12 ;
x [ 12 ] = 13 ;
x [ 13 ] = 14 ;
x [ 14 ] = 15 ;
x [ 15 ] = 16 ;
x [ 16 ] = 17 ;
x [ 17 ] = 18 ;
x [ 18 ] = 19 ;
x [ 19 ] = 20 ;
x [ 20 ] = 21 ;
x [ 21 ] = 22 ;
x [ 22 ] = 23 ;
x [ 23 ] = 24 ;
x [ 24 ] = 25 ;
x [ 25 ] = 26 ;
x [ 26 ] = 27 ;
x [ 27 ] = 28 ;
x [ 28 ] = 29 ;
x [ 29 ] = 30 ;
x [ 30 ] = 31 ;
x [ 31 ] = 32 ;
x [ 32 ] = 33 ;
x [ 33 ] = 34 ;
x [ 34 ] = 35 ;
x [ 35 ] = 36 ;
x [ 36 ] = 37 ;
x [ 37 ] = 38 ;
x [ 38 ] = 39 ;
x [ 39 ] = 40 ;
x [ 40 ] = 41 ;
x [ 41 ] = 42 ;
x [ 42 ] = 43 ;
x [ 43 ] = 44 ;
x [ 44 ] = 45 ;
x [ 45 ] = 46 ;
x [ 46 ] = 47 ;
x [ 47 ] = 48 ;
x [ 48 ] = 49 ;
x [ 49 ] = 50 ;
x [ 50 ] = 51 ;
x [ 51 ] = 52 ;
x [ 52 ] = 53 ;
x [ 53 ] = 54 ;
x [ 54 ] = 55 ;
x [ 55 ] = 56 ;
x [ 56 ] = 57 ;
x [ 57 ] = 58 ;
x [ 58 ] = 59 ;
x [ 59 ] = 60 ;
x [ 60 ] = 61 ;
x [ 61 ] = 62 ;
x [ 62 ] = 63 ;
x [ 63 ] = 64 ;
x [ 64 ] = 65 ;
x [ 65 ] = 66 ;
x [ 66 ] = 67 ;
x [ 67 ] = 68 ;
x [ 68 ] = 69 ;
x [ 69 ] = 70 ;
x [ 70 ] = 71 ;
x [ 71 ] = 72 ;
x [ 72 ] = 73 ;
x [ 73 ] = 74 ;
x [ 74 ] = 75 ;
x [ 75 ] = 76 ;
x [ 76 ] = 77 ;
x [ 77 ] = 78 ;
x [ 78 ] = 79 ;
x [ 79 ] = 80 ;
x [ 80 ] = 81 ;
x [ 81 ] = 82 ;
x [ 82 ] = 83 ;
x [ 83 ] = 84 ;
x [ 84 ] = 85 ;
x [ 85 ] = 86 ;
x [ 86 ] = 87 ;
x [ 87 ] = 88 ;
x [ 88 ] = 89 ;
x [ 89 ] = 90 ;
x [ 90 ] = 91 ;
x [ 91 ] = 92 ;
x [ 92 ] = 93 ;
x [ 93 ] = 94 ;
x [ 94 ] = 95 ;
x [ 95 ] = 96 ;
x [ 96 ] = 97 ;
x [ 97 ] = 98 ;
x [ 98 ] = 99 ;
x [ 99 ] = 100 ;
x [ 100 ] = 101 ;
x [ 101 ] = 102 ;
x [ 102 ] = 103 ;
x [ 103 ] = 104 ;
x [ 104 ] = 105 ;
x [ 105 ] = 106 ;
x [ 106 ] = 107 ;
x [ 107 ] = 108 ;
x [ 108 ] = 109 ;
x [ 109 ] = 110 ;
x [ 110 ] = 111 ;
x [ 111 ] = 112 ;
x [ 112 ] = 113 ;
x [ 113 ] = 114 ;
x [ 114 ] = 115 ;
x [ 115 ] = 116 ;
x [ 116 ] = 117 ;
x [ 117 ] = 118 ;
x [ 118 ] = 119 ;
x [ 119 ] = 120 ;
x [ 120 ] = 121 ;
x [ 121 ] = 122 ;
x [ 122 ] = 123 ;
x [ 123 ] = 124 ;
x [ 124 ] = 125 ;
x [ 125 ] = 126 ;
x [ 126 ] = 127 ;
x [ 127 ] = 128 ;
x [ 128 ] = 129 ;
x [ 129 ] = 130 ;
x [ 130 ] = 131 ;
x [ 131 ] = 132 ;
x [ 132 ] = 133 ;
x [ 133 ] = 134 ;
x [ 134 ] = 135 ;
x [ 135 ] = 136 ;
x [ 136 ] = 137 ;
x [ 137 ] = 138 ;
x [ 138 ] = 139 ;
x [ 139 ] = 140 ;
x [ 140 ] = 141 ;
x [ 141 ] = 142 ;
x [ 142 ] = 143 ;
x [ 143 ] = 144 ;
x [ 144 ] = 145 ;
x [ 145 ] = 146 ;
x [ 146 ] = 147 ;
x [ 147 ] = 148 ;
x [ 148 ] = 149 ;
x [ 149 ] = 150 ;
x [ 150 ] = 151 ;
x [ 151 ] = 152 ;
x [ 152 ] = 153 ;
x [ 153 ] = 154 ;
x [ 154 ] = 155 ;
x [ 155 ] = 156 ;
x [ 156 ] = 157 ;
x [ 157 ] = 158 ;
x [ 158 ] = 159 ;
x [ 159 ] = 160 ;
x [ 160 ] = 161 ;
x [ 161 ] = 162 ;
x [ 162 ] = 163 ;
x [ 163 ] = 164 ;
x [ 164 ] = 165 ;
x [ 165 ] = 166 ;
x [ 166 ] = 167 ;
x [ 167 ] = 168 ;
x [ 168 ] = 169 ;
x [ 169 ] = 170 ;
x [ 170 ] = 171 ;
x [ 171 ] = 172 ;
x [ 172 ] = 173 ;
x [ 173 ] = 174 ;
x [ 174 ] = 175 ;
x [ 175 ] = 176 ;
x [ 176 ] = 177 ;
x [ 177 ] = 178 ;
x [ 178 ] = 179 ;
x [ 179 ] = 180 ;
x [ 180 ] = 181 ;
x [ 181 ] = 182 ;
x [ 182 ] = 183 ;
x [ 183 ] = 184 ;
x [ 184 ] = 185 ;
x [ 185 ] = 186 ;
x [ 186 ] = 187 ;
x [ 187 ] = 188 ;
x [ 188 ] = 189 ;
x [ 189 ] = 190 ;
x [ 190 ] = 191 ;
x [ 191 ] = 192 ;
x [ 192 ] = 193 ;
x [ 193 ] = 194 ;
x [ 194 ] = 195 ;
x [ 195 ] = 196 ;
x [ 196 ] = 197 ;
x [ 197 ] = 198 ;
x [ 198 ] = 199 ;
x [ 199 ] = 200 ;
x [ 200 ] = 201 ;
x [ 201 ] = 202 ;
x [ 202 ] = 203 ;
x [ 203 ] = 204 ;
x [ 204 ] = 205 ;
x [ 205 ] = 206 ;
x [ 206 ] = 207 ;
x [ 207 ] = 208 ;
x [ 208 ] = 209 ;
x [ 209 ] = 210 ;
x [ 210 ] = 211 ;
x [ 211 ] = 212 ;
x [ 212 ] = 213 ;
x [ 213 ] = 214 ;
x [ 214 ] = 215 ;
x [ 215 ] = 216 ;
x [ 216 ] = 217 ;
x [ 217 ] = 218 ;
x [ 218 ] = 219 ;
x [ 219 ] = 220 ;
x [ 220 ] = 221 ;
x [ 221 ] = 222 ;
x [ 222 ] = 223 ;
x [ 223 ] = 224 ;
x [ 224 ] = 225 ;
x [ 225 ] = 226 ;
x [ 226 ] = 227 ;
x [ 227 ] = 228 ;
x [ 228 ] = 229 ;
x [ 229 ] = 230 ;
x [ 230 ] = 231 ;
x [ 231 ] = 232 ;
x [ 232 ] = 233 ;
x [ 233 ] = 234 ;
x [ 234 ] = 235 ;
x [ 235 ] = 236 ;
x [ 236 ] = 237 ;
x [ 237 ] = 238 ;
x [ 238 ] = 239 ;
x [ 239 ] = 240 ;
x [ 240 ] = 241 ;
x [ 241 ] = 242 ;
x [ 242 ] = 243 ;
x [ 243 ] = 244 ;
x [ 244 ] = 245 ;
x [ 245 ] = 246 ;
x [ 246 ] = 247 ;
x [ 247 ] = 248 ;
x [ 248 ] = 249 ;
x [ 249 ] = 250 ;
x [ 250 ] = 251 ;
x [ 251 ] = 252 ;
x [ 252 ] = 253 ;
x [ 253 ] = 254 ;
x [ 254 ] = 255 ;
x [ 255 ] = 256 ;
x [ 256 ] = 257 ;
x [ 257 ] = 258 ;
x [ 258 ] = 259 ;
x [ 259 ] = 260 ;
x [ 260 ] = 261 ;
x [ 261 ] = 262 ;
x [ 262 ] = 263 ;
x [ 263 ] = 264 ;
x [ 264 ] = 265 ;
x [ 265 ] = 266 ;
x [ 266 ] = 267 ;
x [ 267 ] = 268 ;
x [ 268 ] = 269 ;
x [ 269 ] = 270 ;
x [ 270 ] = 271 ;
x [ 271 ] = 272 ;
x [ 272 ] = 273 ;
x [ 273 ] = 274 ;
x [ 274 ] = 275 ;
x [ 275 ] = 276 ;
x [ 276 ] = 277 ;
x [ 277 ] = 278 ;
x [ 278 ] = 279 ;
x [ 279 ] = 280 ;
x [ 280 ] = 281 ;
x [ 281 ] = 282 ;
x [ 282 ] = 283 ;
x [ 283 ] = 284 ;
x [ 284 ] = 285 ;
x [ 285 ] = 286 ;
x [ 286 ] = 287 ;
x [ 287 ] = 288 ;
x [ 288 ] = 289 ;
x [ 289 ] = 290 ;
x [ 290 ] = 291 ;
x [ 291 ] = 292 ;
x [ 292 ] = 293 ;
x [ 293 ] = 294 ;
x [ 294 ] = 295 ;
x [ 295 ] = 296 ;
x [ 296 ] = 297 ;
x [ 297 ] = 298 ;
x [ 298 ] = 299 ;
x [ 299 ] = 300 ;
x [ 300 ] = 301 ;
x [ 301 ] = 302 ;
x [ 302 ] = 303 ;
x [ 303 ] = 304 ;
x [ 304 ] = 305 ;
x [ 305 ] = 306 ;
x [ 306 ] = 307 ;
x [ 307 ] = 308 ;
x [ 308 ] = 309 ;
x [ 309 ] = 310 ;
x [ 310 ] = 311 ;
x [ 311 ] = 312 ;
x [ 312 ] = 313 ;
x [ 313 ] = 314 ;
x [ 314 ] = 315 ;
x [ 315 ] = 316 ;
x [ 316 ] = 317 ;
x [ 317 ] = 318 ;
x [ 318 ] = 319 ;
x [ 319 ] = 320 ;
x [ 320 ] = 321 ;
x [ 321 ] = 322 ;
x [ 322 ] = 323 ;
x [ 323 ] = 324 ;
x [ 324 ] = 325 ;
x [ 325 ] = 326 ;
x [ 326 ] = 327 ;
x [ 327 ] = 328 ;
x [ 328 ] = 329 ;
x [ 329 ] = 330 ;
x [ 330 ] = 331 ;
x [ 331 ] = 332 ;
x [ 332 ] = 333 ;
x [ 333 ] = 334 ;
x [ 334 ] = 335 ;
x [ 335 ] = 336 ;
x [ 336 ] = 337 ;
x [ 337 ] = 338 ;
x [ 338 ] = 339 ;
x [ 339 ] = 340 ;
x [ 340 ] = 341 ;
x [ 341 ] = 342 ;
x [ 342 ] = 343 ;
x [ 343 ] = 344 ;
x [ 344 ] = 345 ;
x [ 345 ] = 346 ;
x [ 346 ] = 347 ;
x [ 347 ] = 348 ;
x [ 348 ] = 349 ;
x [ 349 ] = 350 ;
x [ 350 ] = 351 ;
x [ 351 ] = 352 ;
x [ 352 ] = 353 ;
x [ 353 ] = 354 ;
x [ 354 ] = 355 ;
x [ 355 ] = 356 ;
x [ 356 ] = 357 ;
x [ 357 ] = 358 ;
x [ 358 ] = 359 ;
x [ 359 ] = 360 ;
x [ 360 ] = 361 ;
x [ 361 ] = 362 ;
x [ 362 ] = 363 ;
x [ 363 ] = 364 ;
x [ 364 ] = 365 ;
x [ 365 ] = 366 ;
x [ 366 ] = 367 ;
x [ 367 ] = 368 ;
x [ 368 ] = 369 ;
x [ 369 ] = 370 ;
x [ 370 ] = 371 ;
x [ 371 ] = 372 ;
x [ 372 ] = 373 ;
x [ 373 ] = 374 ;
x [ 374 ] = 375 ;
x [ 375 ] = 376 ;
x [ 376 ] = 377 ;
x [ 377 ] = 378 ;
x [ 378 ] = 379 ;
x [ 379 ] = 380 ;
x [ 380 ] = 381 ;
x [ 381 ] = 382 ;
x [ 382 ] = 383 ;
x [ 383 ] = 384 ;
x [ 384 ] = 385 ;
x [ 385 ] = 386 ;
x [ 386 ] = 387 ;
x [ 387 ] = 388 ;
x [ 388 ] = 389 ;
x [ 389 ] = 390 ;
x [ 390 ] = 391 ;
x [ 391 ] = 392 ;
x [ 392 ] = 393 ;
x [ 393 ] = 394 ;
x [ 394 ] = 395 ;
x [ 395 ] = 396 ;
x [ 396 ] = 397 ;
x [ 397 ] = 398 ;
x [ 398 ] = 399 ;
x [ 399 ] = 400 ;
x [ 400 ] = 401 ;
x [ 401 ] = 402 ;
x [ 402 ] = 403 ;
x [ 403 ] = 404 ;
x [ 404 ] = 405 ;
x [ 405 ] = 406 ;
x [ 406 ] = 407 ;
x [ 407 ] = 408 ;
x [ 408 ] = 409 ;
x [ 409 ] = 410 ;
x [ 410 ] = 411 ;
x [ 411 ] = 412 ;
x [ 412 ] = 413 ;
x [ 413 ] = 414 ;
x [ 414 ] = 415 ;
x [ 415 ] = 416 ;
x [ 416 ] = 417 ;
x [ 417 ] = 418 ;
x [ 418 ] = 419 ;
x [ 419 ] = 420 ;
x [ 420 ] = 421 ;
x [ 421 ] = 422 ;
x [ 422 ] = 423 ;
x [ 423 ] = 424 ;
x [ 424 ] = 425 ;
x [ 425 ] = 426 ;
x [ 426 ] = 427 ;
x [ 427 ] = 428 ;
x [ 428 ] = 429 ;
x [ 429 ] = 430 ;
x [ 430 ] = 431 ;
x [ 431 ] = 432 ;
x [ 432 ] = 433 ;
x [ 433 ] = 434 ;
x [ 434 ] = 435 ;
x [ 435 ] = 436 ;
x [ 436 ] = 437 ;
x [ 437 ] = 438 ;
x [ 438 ] = 439 ;
x [ 439 ] = 440 ;
x [ 440 ] = 441 ;
x [ 441 ] = 442 ;
x [ 442 ] = 443 ;
x [ 443 ] = 444 ;
x [ 444 ] = 445 ;
x [ 445 ] = 446 ;
x [ 446 ] = 447 ;
x [ 447 ] = 448 ;
x [ 448 ] = 449 ;
x [ 449 ] = 450 ;
x [ 450 ] = 451 ;
x [ 451 ] = 452 ;
x [ 452 ] = 453 ;
x [ 453 ] = 454 ;
x [ 454 ] = 455 ;
x [ 455 ] = 456 ;
x [ 456 ] = 457 ;
x [ 457 ] = 458 ;
x [ 458 ] = 459 ;
x [ 459 ] = 460 ;
x [ 460 ] = 461 ;
x [ 461 ] = 462 ;
x [ 462 ] = 463 ;
x [ 463 ] = 464 ;
x [ 464 ] = 465 ;
x [ 465 ] = 466 ;
x [ 466 ] = 467 ;
x [ 467 ] = 468 ;
x [ 468 ] = 469 ;
x [ 469 ] = 470 ;
x [ 470 ] = 471 ;
x [ 471 ] = 472 ;
x [ 472 ] = 473 ;
x [ 473 ] = 474 ;
x [ 474 ] = 475 ;
x [ 475 ] = 476 ;
x [ 476 ] = 477 ;
x [ 477 ] = 478 ;
x [ 478 ] = 479 ;
x [ 479 ] = 480 ;
x [ 480 ] = 481 ;
x [ 481 ] = 482 ;
x [ 482 ] = 483 ;
x [ 483 ] = 484 ;
x [ 484 ] = 485 ;
x [ 485 ] = 486 ;
x [ 486 ] = 487 ;
x [ 487 ] = 488 ;
x [ 488 ] = 489 ;
x [ 489 ] = 490 ;
x [ 490 ] = 491 ;
x [ 491 ] = 492 ;
x [ 492 ] = 493 ;
x [ 493 ] = 494 ;
x [ 494 ] = 495 ;
x [ 495 ] = 496 ;
x [ 496 ] = 497 ;
x [ 497 ] = 498 ;
x [ 498 ] = 499 ;
x [ 499 ] = 500 ;
x [ 500 ] = 501 ;
x [ 501 ] = 502 ;
x [ 502 ] = 503 ;
x [ 503 ] = 504 ;
x [ 504 ] = 505 ;
x [ 505 ] = 506 ;
x [ 506 ] = 507 ;
x [ 507 ] = 508 ;
x [ 508 ] = 509 ;
x [ 509 ] = 510 ;
x [ 510 ] = 511 ;
x [ 511 ] = 512 ;
a[1]=11; // ýòî çàäàåì òî ÷òî âûâîäèì , äàííûå
a[2]=25;
a[3]=37;
a[4]=49;
n_in_massiv=1; // ïîõèöèÿ êîòîðóþ âûâîäèì íà ýêðàí
while (1)
{
// Place your code here
/*çàïîëíåíèå ìàñèâà*/
/*Ïîñëàòü ñèíõðîèìïóëüñ*/
/*ïîñëàòü äàíûå*/
//n_in_massiv_x=1; // ïîõèöèÿ êîòîðóþ âûâîäèì íà ýêðàí
//index = 2;
// +++++++++++++++ýòî ôóíêöèÿ âûâîäà íà ýêðàí ñëä 1602 ++++++++++++++++++++++++++
lcd_clear(); // î÷èùàåì äèñïëåé÷èê
lcd_gotoxy(0,0);
//lcd_putsf("1234");
sprintf(string, "%4d",x[(0+n_in_massiv)]);
lcd_puts(string);
//lcd_putsf(" ");
sprintf(string, "%4d", x[1+n_in_massiv]);
lcd_puts(string);
// lcd_putsf(" ");
sprintf(string, "%4d", x[2+n_in_massiv]);
lcd_puts(string);
//lcd_putsf(" ");
sprintf(string, "%4d", x[3+n_in_massiv]);
lcd_puts(string);
// lcd_putsf(" ");
lcd_gotoxy(0,1);
sprintf(string, "%4d",a[(0+n_in_massiv)]); // äîáàâëÿåì ê 0 íîìåð ìàññèâà è âûâîäèì åãî
lcd_puts(string);
//lcd_putsf(" "); // îñòàëîñü èç çà ãëþêà ñ íåñîâïàäåíèå ðàçìåðà ìààñèâà 3 è 4
sprintf(string, "%4d", a[1+n_in_massiv]); // âûâîæèì â äåñÿòè÷íîé ôîðìå, 4 çíàêà â ìàññèâå, íóëè íå äîáàâëÿåì
lcd_puts(string);
// lcd_putsf(" ");
sprintf(string, "%4d", a[2+n_in_massiv]); // âûâîäè ïåðåìíûûóþ "à", îòôîðìàòèðîâàô âñå â òðîêó
lcd_puts(string);
//lcd_putsf(" ");
sprintf(string, "%4d", a[3+n_in_massiv]); // òîåñòü âûâîäèì ñòðîêó
lcd_puts(string);
// lcd_putsf(" ");
// íàæàòèå êíîïîê îòðàáàòûâàåì +++++++++++++++++++++++++++++++++++++++++++
// òóò ìû ïðîâåðÿåò íå íàæàòà ëè êíîïêà ýôôåêòîâ +> это рабаотает, кнопка кн1
if ((PINC.0 == 0)&&(PINC.6 == 1)){ //+ åñëè íàæàòà êíîïêà 5
TCCR1A = 0x00; //stop timer îñíîâíîé òàéìåð ïî êîòîðîìó èäåò ïðîâåðêà
TCCR1B = 0x00; //stop timer
TCNT1L = 0x01; //çàïèñàòü â ðåãèñòð òàéìåðà ÷èñëî 1
TCNT1H= 0x00;
TCCR1B = 0b00000100; //start timer - clock/-4
kn1=0;
kn2=0;
kn1++;
}
if ((TCNT1L > 200)&&(kn1>0)&&(PINC.0 == 1)&&(PINC.6 == 1)) { // ïî åå îòæàòèþ è ðàáîòå òàéìåðà
TCNT1L = 0x00; //stop timer
TCNT1H= 0x00;
TCNT1L = 0x01; //çàïèñàòü â ðåãèñòð òàéìåðà ÷èñëî 0
TCNT1H= 0x00;
kn1=0;
n_in_massiv++; // óâåëè÷èòü ñ÷åò÷èê ýôôåêòîâ íà 1
}
// òóò ìû ïðîâåðÿåò íå íàæàòà ëè êíîïêà ýôôåêòîâ +> çàêîí÷èëîñü
// òóò ìû ïðîâåðÿåò íå íàæàòà ëè êíîïêà ýôôåêòîâ <-
if ((PINC.6 == 0)&&(PINC.0 == 1)){ // + åñëè íàæàòà êíîïêà 7
TCCR1A = 0x00; //stop timer îñíîâíîé òàéìåð ïî êîòîðîìó èäåò ïðîâåðêà
TCCR1B = 0x00; //stop timer
TCNT1L = 0x01; //çàïèñàòü â ðåãèñòð òàéìåðà ÷èñëî 1
TCNT1H= 0x00;
TCCR1B = 0b00000100; //start timer - clock/-4
// ÇÀÏÓÑÊÀÅÌ Ñ×ÊÒ×ÈÊ ÊÍÎÏÊÈ
kn1=0;
kn2=0;
kn2++;
}
if ((TCNT1L > 200)&&(kn2>0)&&(PINC.6 == 1)&&(PINC.0 == 1)) { // это рабаотает, кн 2
TCNT1L = 0x00; //stop timer
TCNT1H= 0x00;
TCNT1L = 0x01; //çàïèñàòü â ðåãèñòð òàéìåðà ÷èñëî 0
TCNT1H= 0x00;
n_in_massiv = n_in_massiv-1; // ñ÷åò÷èê ýôôåêòîâ - 1
kn2=0; // òóò áûëî ==0?
}
// òóò ìû ïðîâåðÿåò íå íàæàòà ëè êíîïêà ýôôåêòîâ <- çàêîí÷èëîñü
// òóò ìû ïðîâåðÿåò íå íàæàòà ëè êíîïêà ýôôåêòîâ + äàííûå
/*
if ((PINC.4 == 1)&&(PINC.2 == 0)){ // + åñëè íàæàòà êíîïêà 7
TCCR1A = 0x00; //stop timer îñíîâíîé òàéìåð ïî êîòîðîìó èäåò ïðîâåðêà
TCCR1B = 0x00; //stop timer
TCNT1L = 0x01; //çàïèñàòü â ðåãèñòð òàéìåðà ÷èñëî 1
TCNT1H= 0x00;
TCCR1B = 0b00000100; //start timer - clock/-4
// ÇÀÏÓÑÊÀÅÌ Ñ×ÊÒ×ÈÊ ÊÍÎÏÊÈ
// kn3=0;
// kn4=0;
kn3=1;
}
//if ((PINC.4 == 1)&&(PINC.2 == 0)){ // + åñëè íàæàòà êíîïêà 7
// a[n_in_massiv] = a[n_in_massiv]+1 ; // ñ÷åò÷èê ýôôåêòîâ - 1не рабаотает
// }
if ((TCNT1L > 200)&&(kn3>0)&&(PINC.4 == 1)&&(PINC.2 == 1)) { //
// TCNT1L = 0x00; //stop timer
// TCNT1H= 0x00;
TCCR1A = 0x00; //stop timer îñíîâíîé òàéìåð ïî êîòîðîìó èäåò ïðîâåðêà
TCCR1B = 0x00; //stop timer
TCNT1L = 0x01; //çàïèñàòü â ðåãèñòð òàéìåðà ÷èñëî 0
TCNT1H= 0x00;
a[n_in_massiv] = a[n_in_massiv]-1 ; // ñ÷åò÷èê ýôôåêòîâ - 1
kn3=0; // òóò áûëî ==0?
}
*/
// òóò ìû ïðîâåðÿåò íå íàæàòà ëè êíîïêà ýôôåêòîâ - äàííûå работает кн4
if ((PINC.4 == 1)&&(PINC.2 == 0)){ // + åñëè íàæàòà êíîïêà 7
TCCR1A = 0x00; //stop timer îñíîâíîé òàéìåð ïî êîòîðîìó èäåò ïðîâåðêà
TCCR1B = 0x00; //stop timer
TCNT1L = 0x01; //çàïèñàòü â ðåãèñòð òàéìåðà ÷èñëî 1
TCNT1H= 0x00;
TCCR1B = 0b00000100; //start timer - clock/-4
// ÇÀÏÓÑÊÀÅÌ Ñ×ÊÒ×ÈÊ ÊÍÎÏÊÈ
kn3=0;
kn3++;
kn4=0;
}
if ((TCNT1L > 200)&&(kn3>0)&&(PINC.4 == 1)&&(PINC.2 == 1)) { // ïî åå îòæàòèþ è ðàáîòå òàéìåðà È Ñ×ÅÒ×ÈÊÀ ÊÍÎÏÊÈ
TCNT1L = 0x00; //stop timer
TCNT1H= 0x00;
TCNT1L = 0x01; //çàïèñàòü â ðåãèñòð òàéìåðà ÷èñëî 0
TCNT1H= 0x00;
a[n_in_massiv] = a[n_in_massiv]+1 ; // ñ÷åò÷èê ýôôåêòîâ - 1
kn3=0; // òóò áûëî ==0?
kn4=0;
}
// òóò ìû ïðîâåðÿåò íå íàæàòà ëè êíîïêà ýôôåêòîâ + äàííûå çàêîí÷èëîñü
// òóò ìû ïðîâåðÿåò íå íàæàòà ëè êíîïêà ýôôåêòîâ - äàííûå
if ((PINC.4 == 0)&&(PINC.2 == 1)){ // + åñëè íàæàòà êíîïêà 7
TCCR1A = 0x00; //stop timer îñíîâíîé òàéìåð ïî êîòîðîìó èäåò ïðîâåðêà
TCCR1B = 0x00; //stop timer
TCNT1L = 0x01; //çàïèñàòü â ðåãèñòð òàéìåðà ÷èñëî 1
TCNT1H= 0x00;
TCCR1B = 0b00000100; //start timer - clock/-4
// ÇÀÏÓÑÊÀÅÌ Ñ×ÊÒ×ÈÊ ÊÍÎÏÊÈ
kn3=0;
kn4=0;
kn4++;
}
if ((TCNT1L > 200)&&(kn4>0)&&(PINC.4 == 1)&&(PINC.2 == 1)) { // ïî åå îòæàòèþ è ðàáîòå òàéìåðà È Ñ×ÅÒ×ÈÊÀ ÊÍÎÏÊÈ
TCNT1L = 0x00; //stop timer
TCNT1H= 0x00;
TCNT1L = 0x01; //çàïèñàòü â ðåãèñòð òàéìåðà ÷èñëî 0
TCNT1H= 0x00;
a[n_in_massiv] = a[n_in_massiv]-1 ; // ñ÷åò÷èê ýôôåêòîâ - 1
kn4=0; // òóò áûëî ==0?
}
// òóò ìû ïðîâåðÿåò íå íàæàòà ëè êíîïêà ýôôåêòîâ - äàííûå çàêîí÷èëîñü
// ++++++ ýòî ïðîâåðêà ÷òîáû íîìåðà ýôôôåêòîâ íå óáåæàëè çà ïðåäåëû +++++++++
if (n_in_massiv==65364){ // âñåãî 42 ýôôåêòîâ ïîêà, áîëüøå íà ýêðàí íå âûâîäèì
n_in_massiv=512; // ýôôåêòû êîí÷èëèñü, ñáðàñûâàåì èõ ñ÷åò÷èê (ñòàâèì ýòó ñòðî÷êó ïåðâîé)
}
if (n_in_massiv>511){ // âñåãî 42 ýôôåêòîâ ïîêà, áîëüøå íà ýêðàí íå âûâîäèì
n_in_massiv=1; // ýôôåêòû êîí÷èëèñü, ñáðàñûâàåì èõ ñ÷åò÷èê
}
if (a[n_in_massiv]==255){ // âñåãî 42 ýôôåêòîâ ïîêà, áîëüøå íà ýêðàí íå âûâîäèì
a[n_in_massiv]=254; // ýôôåêòû êîí÷èëèñü, ñáðàñûâàåì èõ ñ÷åò÷èê (ñòàâèì ýòó ñòðî÷êó ïåðâîé)
}
if (a[n_in_massiv]==0){ // âñåãî 42 ýôôåêòîâ ïîêà, áîëüøå íà ýêðàí íå âûâîäèì
a[n_in_massiv]=1; // ýôôåêòû êîí÷èëèñü, ñáðàñûâàåì èõ ñ÷åò÷èê (ñòàâèì ýòó ñòðî÷êó ïåðâîé)
}
// ++++++ ýòî ïðîâåðêà ÷òîáû íîìåðà ýôôôåêòîâ íå óáåæàëè çà ïðåäåëû çàêîí÷èëàñü +++++++++
//delay_ms(2000); // çàäåðæêà , æäåì
/*
for (index=0;index<sizeof(a); index++)
{
Uart_send(a[index]);
}
*/
};
}
Добавлено спустя 10 минут 13 секунд:Если ставлю в тексте кн4, то при нажатии кнопки переменная прибавляется..
(по обоим кнопкам)
а если кн3 или кн5 - то нет... жуть..
кнопки кн 1 и кн 2 работают нормально, хотя код такой же..