СХЕМА.RU - Радиолюбительский портал » Другие новости радиолюбителя » Смена Типа Индикатора В С Коде Для Atmega8

Смена Типа Индикатора В С Коде Для Atmega8

27-09-2012, 11:26 От: admin Посмотрели: 1365
Всем привет! Решил собрать себе вольтамперметр в БП. Нашел схему http://elwo.ru/publ/voltampermetr_na_mikrokontrollere_v_laboratornyj_bp/1-1-0-413 Там используются индикаторы с общим катодом, а у меня индикаторы с анодом. Соответственно надо поменять прошивку, и заодно выкинуть четвертый сегмент(мне он не нужен, можно просто не подключать, но раз сунулись в код, то можно и убрать. Код на С:


/*****************************************************
This program was produced by the
CodeWizardAVR V2.03.4 Standard
Automatic Program Generator
© Copyright 1998-2008 Pavel Haiduc, HP InfoTech s.r.l.
http://www.hpinfotech.com
Project :
Version :
Date : 13.03.2009
Author :
Company :
Comments:

Chip type : ATmega8
Program type : Application
Clock frequency : 4,000000 MHz
Memory model : Small
External RAM size : 0
Data Stack size : 256
*****************************************************/
#include <mega8.h>
#include <delay.h>
#define digit1 PORTB.5 //4 анод индикатора
#define digit2 PORTB.4 //3 анод
#define digit3 PORTB.3 //2 анод
#define digit4 PORTB.2 //1 анод
#define KEY_IND 0
#define IND_U 0
#define IND_I 1
#define IND_P 2
#define IND_OL 3
#define IND_NO 4
#define FIRST_ADC_INPUT 0
#define LAST_ADC_INPUT 1
unsigned int adc_data[LAST_ADC_INPUT-FIRST_ADC_INPUT+1];
char digit_out[4], cur_dig, a, indicate;
unsigned long indication;
unsigned long volt, amper;
#define ADC_VREF_TYPE 0xC0
#define VREF 2620UL
flash char digits[] = {
0b00111111, //0
0b00000110, //1
0b01011011, //2
0b01001111, //3
0b01100110, //4
0b01101101, //5
0b01111101, //6
0b00000111, //7
0b01111111, //8
0b01101111 //9
};
// ADC interrupt service routine
// with auto input scanning
interrupt [ADC_INT] void adc_isr(void)
{
static unsigned char input_index=0;
// Read the AD conversion result
adc_data[input_index]=ADCW;
// Select next ADC input
if (++input_index > (LAST_ADC_INPUT-FIRST_ADC_INPUT))
input_index=0;
ADMUX=(FIRST_ADC_INPUT | (ADC_VREF_TYPE & 0xff))+input_index;
// Delay needed for the stabilization of the ADC input voltage
delay_us(10);
// Start the AD conversion
ADCSRA|=0x40;
}
void recoding(void) {

if (indication<10000)
{
//digit_out[0]=indication%10;
indication=indication/10;
digit_out[1]=indication%10;
indication=indication/10;
digit_out[2]=indication%10;
indication=indication/10;
digit_out[3]=indication%10;
a=3;
}
if ((indication>=10000)&&(indication<100000))
{
indication=indication/10;
//digit_out[0]=indication%10;
indication=indication/10;
digit_out[1]=indication%10;
indication=indication/10;
digit_out[2]=indication%10;
indication=indication/10;
digit_out[3]=indication%10;
a=2;
}

if ((indication>=100000)&&(indication<1000000))
{
indication=indication/100;
//digit_out[0]=indication%10;
indication=indication/10;
digit_out[1]=indication%10;
indication=indication/10;
digit_out[2]=indication%10;
indication=indication/10;
digit_out[3]=indication%10;
a=1;
}

if (indication>=1000000)
{
indication=indication/1000;
//digit_out[0]=indication%10;
indication=indication/10;
digit_out[1]=indication%10;
indication=indication/10;
digit_out[2]=indication%10;
indication=indication/10;
digit_out[3]=indication%10;
}

}
// Timer 2 overflow interrupt service routine
interrupt [TIM2_OVF] void timer2_ovf_isr(void)
{
switch (cur_dig){
case 0:{digit4=1;digit1=0;break;};
case 1:{digit1=1;digit2=0;break;};
case 2:{digit2=1;digit3=0;break;};
case 3:{digit3=1;digit4=0;break;};
}
PORTD=digits[digit_out[cur_dig]];
if(cur_dig==0)if(a==0)PORTD.7=1; //четвертая точка
if(cur_dig==1)if(a==1)PORTD.7=1; //третья точка
if(cur_dig==2)if(a==2)PORTD.7=1; //вторая точка
if(cur_dig==3)if(a==3)PORTD.7=1; //первая точка

if(indicate==IND_U)
{
//if(cur_dig==0){PORTD=0x40;}
if(cur_dig==0){PORTD=0x3E;}
//if(cur_dig==2){PORTD=0x40;}
//if(cur_dig==3){PORTD=0x00;}
}

if(indicate==IND_I)
{
//if(cur_dig==0){PORTD=0x40;}
if(cur_dig==0){PORTD=0x77;}
//if(cur_dig==2){PORTD=0x40;}
//if(cur_dig==3){PORTD=0x00;}
}

if(indicate==IND_P)
{
if(cur_dig==0){PORTD=0x40;}
if(cur_dig==1){PORTD=0x73;}
if(cur_dig==2){PORTD=0x40;}
if(cur_dig==3){PORTD=0x00;}
}

if(indicate==IND_OL)
{
if(cur_dig==0){PORTD=0x00;}
if(cur_dig==1){PORTD=0x38;}
if(cur_dig==2){PORTD=0xBF;}
if(cur_dig==3){PORTD=0x00;}
}

cur_dig++;
if (cur_dig==4) cur_dig=0;
}
void main(void)
{
// Declare your local variables here
// Input/Output Ports initialization
// Port B initialization
// Func7=In Func6=In Func5=Out Func4=Out Func3=Out Func2=Out Func1=In Func0=In
// State7=P State6=P State5=1 State4=1 State3=1 State2=1 State1=P State0=P
PORTB=0xFF;
DDRB=0x3C;
// Port C initialization
// Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State6=P State5=P State4=P State3=P State2=P State1=T State0=T
PORTC=0x7C;
DDRC=0x00;
// Port D 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
PORTD=0x00;
DDRD=0xFF;

// Timer/Counter 0 initialization
// Clock source: System Clock
// Clock value: Timer 0 Stopped
TCCR0=0x00;
TCNT0=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: 125,000 kHz
// Mode: Normal top=FFh
// OC2 output: Disconnected
ASSR=0x00;
TCCR2=0x03;
TCNT2=0x00;
OCR2=0x00;
// External Interrupt(s) initialization
// INT0: Off
// INT1: Off
MCUCR=0x00;
// Timer(s)/Counter(s) Interrupt(s) initialization
TIMSK=0x40;
// Analog Comparator initialization
// Analog Comparator: Off
// Analog Comparator Input Capture by Timer/Counter 1: Off
ACSR=0x80;
SFIOR=0x00;
// ADC initialization
// ADC Clock frequency: 62,500 kHz
// ADC Voltage Reference: Int., cap. on AREF
ADMUX=FIRST_ADC_INPUT | (ADC_VREF_TYPE & 0xff);
ADCSRA=0xCE;
// Global enable interrupts
#asm("sei")
while (1)
{
volt=(adc_data[0]*VREF/1024)*48;
amper=(adc_data[1]*VREF/1024)*10;
delay_ms(250);
if (PINB.0==1) {indication=volt;indicate=IND_U;}
if (PINB.0==0) {indication=amper;indicate=IND_I;}
if ((volt>=110000)||(amper>=11000)) indicate=IND_OL;
recoding();
}
}

Из понятного мне и относящегося к индикаторам тут только:


flash char digits[] = {
0b00111111, //0
0b00000110, //1
0b01011011, //2
0b01001111, //3
0b01100110, //4
0b01101101, //5
0b01111101, //6
0b00000111, //7
0b01111111, //8
0b01101111 //9
};



Тут для работы с общим анодом надо поменять все 0 на 1, а все 1 на 0. Верно? Но тоже самое надо сделать и с управлением анодами(катодами), а вот его я найти не могу. Пожалуйста, ткните носом в него.

П.С. Я начинающий, строго не судить. И хочется во всем самому разобраться. Зарание всем спасибо.
Раздел: AVR

Уважаемый посетитель, Вы зашли на сайт как незарегистрированный пользователь.
Мы рекомендуем Вам зарегистрироваться, либо войти на сайт под своим именем.

Обсудить на форуме


На момент добавления Смена Типа Индикатора В С Коде Для Atmega8 все ссылки были рабочие.
Все публикации статей, книг и журналов, представлены на этом сайте, исключительно для ознакомления,
авторские права на эти публикации принадлежат авторам статей, книг и издательствам журналов!
Подробно тут | Жалоба

Добавление комментария

Ваше имя:*
E-Mail:*
Текст:
Вопрос:
Решите уравнения x+2x=789
Ответ:*
Введите два слова, показанных на изображении:



Опрос

Ваши предпочтения в TRX


Одинарное преобразование
Двойное преобразование
Прямое преобразование
SDR
Другое
Мне всё равно

Календарь новостей
«    Апрель 2024    »
ПнВтСрЧтПтСбВс
1234567
891011121314
15161718192021
22232425262728
2930