Люди выручайте, вопрос жизни и смерти, нужно перевести прошивку из ATMEGA8 для pic16f76
вот код:
Код:
/*****************************************************
Chip type : ATmega8
Program type : Application
Clock frequency : 1,000000 MHz
Memory model : Small
External SRAM size : 0
Data Stack size : 256
*****************************************************/
#include <mega8.h>
unsigned char nom_temp;
unsigned int imp,kmh;
void init(void);
void display(unsigned char ch,unsigned char nom);
interrupt [EXT_INT0] void ext_int0_isr(void)
{
}
interrupt [EXT_INT1] void ext_int1_isr(void)
{
imp++;
}
interrupt [TIM0_OVF] void timer0_ovf_isr(void)
{
if (nom_temp<3) nom_temp++; else nom_temp=1;
switch (nom_temp)
{
case 1: {if (kmh>99) display((kmh/100)%10,3); break;}
case 2: {if (kmh>9) display((kmh/10)%10,2);break;}
case 3: {display(kmh%10,1);break;}
}
}
// Timer 1 output compare A interrupt service routine
interrupt [TIM1_COMPA] void timer1_compa_isr(void)
{
//kmh=imp*9/5;
kmh=imp*79/100;
//imp_s=imp;
imp=0;
TCNT1H=0x00;
TCNT1L=0x00;
}
void init(void)
{
PORTB=0x00;
DDRB=0xff;
PORTC=0x00;
DDRC=0xff;
// Port D initialization
// Func7=Out Func6=Out Func5=Out Func4=Out Func3=In Func2=Out Func1=Out Func0=Out
// State7=0 State6=0 State5=0 State4=0 State3=P State2=0 State1=0 State0=0
PORTD=0x08;
DDRD=0xF7;
// Timer/Counter 0 initialization
// Clock source: System Clock
// Clock value: 15,625 kHz
//TCCR0=0x03;
// Clock value: 125,000 kHz
TCCR0=0x02;
TCNT0=0x00;
// Timer/Counter 1 initialization
// Clock source: System Clock
// Clock value: 3,906 kHz
// 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: On
// Compare B Match Interrupt: Off
TCCR1A=0x00;
TCCR1B=0x04;
TCNT1H=0x00;
TCNT1L=0x00;
ICR1H=0x00;
ICR1L=0x00;
OCR1AH=0x07;
OCR1AL=0xA1;
OCR1BH=0x00;
OCR1BL=0x00;
// External Interrupt(s) initialization
// INT0: On
// INT0 Mode: Falling Edge
// INT1: On
// INT1 Mode: Falling Edge
GIFR=0x00;
MCUCR=0x0A;
GICR|=0xC0;
// Timer(s)/Counter(s) Interrupt(s) initialization
TIMSK=0x51;
// Analog Comparator initialization
// Analog Comparator: Off
// Analog Comparator Input Capture by Timer/Counter 1: Off
ACSR=0x80;
SFIOR=0x00;
// Global enable interrupts
#asm("sei")
}
void display(unsigned char ch,unsigned char nom)
{
PORTD.0=0;PORTD.1=0;PORTD.2=0;
PORTB.0=1;PORTB.1=1;PORTB.2=1;PORTB.3=1;PORTB.4=1;PORTB.5=1;PORTB.6=1;
switch (ch)
{case 0: {PORTB.1=0;PORTB.2=0;PORTD.7=0;PORTD.6=0;PORTD.5=0;PORTB.0=0;PORTD.4=1;break;}
case 1: {PORTB.1=1;PORTB.2=0;PORTD.7=0;PORTD.6=1;PORTD.5=1;PORTB.0=1;PORTD.4=1;break;}
case 2: {PORTB.1=0;PORTB.2=0;PORTD.7=1;PORTD.6=0;PORTD.5=0;PORTB.0=1;PORTD.4=0;break;}
case 3: {PORTB.1=0;PORTB.2=0;PORTD.7=0;PORTD.6=0;PORTD.5=1;PORTB.0=1;PORTD.4=0;break;}
case 4: {PORTB.1=1;PORTB.2=0;PORTD.7=0;PORTD.6=1;PORTD.5=1;PORTB.0=0;PORTD.4=0;break;}
case 5: {PORTB.1=0;PORTB.2=1;PORTD.7=0;PORTD.6=0;PORTD.5=1;PORTB.0=0;PORTD.4=0;break;}
case 6: {PORTB.1=0;PORTB.2=1;PORTD.7=0;PORTD.6=0;PORTD.5=0;PORTB.0=0;PORTD.4=0;break;}
case 7: {PORTB.1=0;PORTB.2=0;PORTD.7=0;PORTD.6=1;PORTD.5=1;PORTB.0=1;PORTD.4=1;break;}
case 8: {PORTB.1=0;PORTB.2=0;PORTD.7=0;PORTD.6=0;PORTD.5=0;PORTB.0=0;PORTD.4=0;break;}
case 9: {PORTB.1=0;PORTB.2=0;PORTD.7=0;PORTD.6=0;PORTD.5=1;PORTB.0=0;PORTD.4=0;break;}
case 10: {PORTB.1=0;PORTB.2=1;PORTD.7=1;PORTD.6=1;PORTD.5=1;PORTB.0=1;PORTD.4=1;break;}
}
switch (nom)
{
case 1: {PORTD.0=1;PORTD.1=0;PORTD.2=0;break;}
case 2: {PORTD.0=0;PORTD.1=1;PORTD.2=0;break;}
case 3: {PORTD.0=0;PORTD.1=0;PORTD.2=1;break;}
}
}
void main(void)
{init();
while (1)
{
};
}