В компиляции ошибок нет но резистор не управляется и никак не реагирует.
Сопротивление mcp41010 должно менятся от минимального до максимального в цикле.
PORTA.6 соединён с CS
PORTA.5 соединён с SCK
PORTA.4 соединён с SI
Листинг программы на Си:
CODE
/*****************************************************
This program was produced by the
CodeWizardAVR V2.04.5a Evaluation
Automatic Program Generator
© Copyright 1998-2009 Pavel Haiduc, HP InfoTech s.r.l.
http://www.hpinfotech.com
Project :
Version :
Date : 20.06.2012
Author : Freeware, for evaluation and non-commercial use only
Company :
Comments:
Chip type : ATtiny261
AVR Core Clock frequency: 4,000000 MHz
Memory model : Tiny
External RAM size : 0
Data Stack size : 32
*****************************************************/
#include <tiny261.h>
#include <delay.h>
// Declare your global variables here
int i;
void CommandTheResistor (unsigned short R)
{
PORTA.5=1;
delay_us(70);
PORTA.6=0;
delay_us(30);
PORTA.5=0; //first clock
delay_us(100);
PORTA.5=1;
delay_us(100);
PORTA.5=0; //second clock
PORTA.4=0;
delay_us(100);
PORTA.5=1;
delay_us(30);
PORTA.4=1;
delay_us(70);
PORTA.5=0; //third clock
delay_us(100);
PORTA.5=1;
delay_us(30);
PORTA.4=0;
delay_us(70);
PORTA.5=0; //fourth clock
delay_us(100);
PORTA.5=1;
delay_us(100);
PORTA.5=0; //fifth clock
delay_us(100);
PORTA.5=1;
delay_us(100);
PORTA.5=0; //sixth clock
delay_us(100);
PORTA.5=1;
delay_us(30);
PORTA.4=1;
delay_us(70);
PORTA.5=0; //seventh clock
delay_us(100);
PORTA.5=1;
delay_us(30);
PORTA.4=0;
delay_us(70);
PORTA.5=0; //eighth clock
delay_us(100);
for(i = 0; i<=7; i++)
{
PORTA.5=1;
delay_us(30);
PORTA.4 = R%2;
R=R/2;
delay_us(70);
PORTA.5=0;
delay_us(100);
}
PORTA.6 = 1;
}
void main(void)
{
// Declare your local variables here
unsigned short RESISTANCE;
// 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=In Func6=Out Func5=Out Func4=Out Func3=In Func2=In Func1=In Func0=In
// State7=T State6=0 State5=0 State4=0 State3=T State2=T State1=T State0=T
PORTA=0x00;
DDRA=0x70;
// Port B 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
PORTB=0x00;
DDRB=0x00;
// Timer/Counter 0 initialization
// Clock source: System Clock
// Clock value: Timer 0 Stopped
// Mode: 8bit top=FFh
TCCR0A=0x00;
TCCR0B=0x00;
TCNT0H=0x00;
TCNT0L=0x00;
OCR0A=0x00;
OCR0B=0x00;
// Timer/Counter 1 initialization
// Clock source: System Clock
// Clock value: Timer1 Stopped
// Mode: Normal top=OCR1C
// OC1A output: Discon.
// OC1B output: Discon.
// OC1C output: Discon.
// Fault Protection Mode: Off
// Fault Protection Noise Canceler: Off
// Fault Protection triggered on Falling edge
// Fault Protection triggered by the Analog Comparator: Off
// Dead Time Rising Edge: 0.000 us
// Dead Time Falling Edge: 0.000 us
// Timer1 Overflow Interrupt: Off
// Compare A Match Interrupt: Off
// Compare B Match Interrupt: Off
// Compare D Match Interrupt: Off
// Fault Protection Interrupt: Off
PLLCSR=0x00;
TCCR1A=0x00;
TCCR1B=0x00;
TCCR1C=0x00;
TCCR1D=0x00;
TCCR1E=0x00;
TC1H=0x00;
TCNT1=0x00;
TC1H=0x00;
OCR1A=0x00;
TC1H=0x00;
OCR1B=0x00;
TC1H=0x00;
OCR1C=0x00;
TC1H=0x00;
OCR1D=0x00;
DT1=0x00;
// External Interrupt(s) initialization
// INT0: Off
// INT1: Off
// Interrupt on any change on pins PCINT0-7, 12-15: Off
// Interrupt on any change on pins PCINT8-11: Off
MCUCR=0x00;
GIMSK=0x00;
// Timer(s)/Counter(s) Interrupt(s) initialization
TIMSK=0x00;
// Universal Serial Interface initialization
// Mode: Disabled
// Clock source: Register & Counter=no clk.
// USI Counter Overflow Interrupt: Off
USICR=0x00;
// Analog Comparator initialization
// Analog Comparator: Off
ACSRA=0x80;
// Hysterezis level: 0 mV
ACSRB=0x00;
while (1)
{
PORTA.5=0;
PORTA.6=1;
PORTA.4=0;
for(RESISTANCE = 0; RESISTANCE<=253; RESISTANCE++)
{CommandTheResistor(RESISTANCE);
delay_us(10000);}
};
}
This program was produced by the
CodeWizardAVR V2.04.5a Evaluation
Automatic Program Generator
© Copyright 1998-2009 Pavel Haiduc, HP InfoTech s.r.l.
http://www.hpinfotech.com
Project :
Version :
Date : 20.06.2012
Author : Freeware, for evaluation and non-commercial use only
Company :
Comments:
Chip type : ATtiny261
AVR Core Clock frequency: 4,000000 MHz
Memory model : Tiny
External RAM size : 0
Data Stack size : 32
*****************************************************/
#include <tiny261.h>
#include <delay.h>
// Declare your global variables here
int i;
void CommandTheResistor (unsigned short R)
{
PORTA.5=1;
delay_us(70);
PORTA.6=0;
delay_us(30);
PORTA.5=0; //first clock
delay_us(100);
PORTA.5=1;
delay_us(100);
PORTA.5=0; //second clock
PORTA.4=0;
delay_us(100);
PORTA.5=1;
delay_us(30);
PORTA.4=1;
delay_us(70);
PORTA.5=0; //third clock
delay_us(100);
PORTA.5=1;
delay_us(30);
PORTA.4=0;
delay_us(70);
PORTA.5=0; //fourth clock
delay_us(100);
PORTA.5=1;
delay_us(100);
PORTA.5=0; //fifth clock
delay_us(100);
PORTA.5=1;
delay_us(100);
PORTA.5=0; //sixth clock
delay_us(100);
PORTA.5=1;
delay_us(30);
PORTA.4=1;
delay_us(70);
PORTA.5=0; //seventh clock
delay_us(100);
PORTA.5=1;
delay_us(30);
PORTA.4=0;
delay_us(70);
PORTA.5=0; //eighth clock
delay_us(100);
for(i = 0; i<=7; i++)
{
PORTA.5=1;
delay_us(30);
PORTA.4 = R%2;
R=R/2;
delay_us(70);
PORTA.5=0;
delay_us(100);
}
PORTA.6 = 1;
}
void main(void)
{
// Declare your local variables here
unsigned short RESISTANCE;
// 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=In Func6=Out Func5=Out Func4=Out Func3=In Func2=In Func1=In Func0=In
// State7=T State6=0 State5=0 State4=0 State3=T State2=T State1=T State0=T
PORTA=0x00;
DDRA=0x70;
// Port B 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
PORTB=0x00;
DDRB=0x00;
// Timer/Counter 0 initialization
// Clock source: System Clock
// Clock value: Timer 0 Stopped
// Mode: 8bit top=FFh
TCCR0A=0x00;
TCCR0B=0x00;
TCNT0H=0x00;
TCNT0L=0x00;
OCR0A=0x00;
OCR0B=0x00;
// Timer/Counter 1 initialization
// Clock source: System Clock
// Clock value: Timer1 Stopped
// Mode: Normal top=OCR1C
// OC1A output: Discon.
// OC1B output: Discon.
// OC1C output: Discon.
// Fault Protection Mode: Off
// Fault Protection Noise Canceler: Off
// Fault Protection triggered on Falling edge
// Fault Protection triggered by the Analog Comparator: Off
// Dead Time Rising Edge: 0.000 us
// Dead Time Falling Edge: 0.000 us
// Timer1 Overflow Interrupt: Off
// Compare A Match Interrupt: Off
// Compare B Match Interrupt: Off
// Compare D Match Interrupt: Off
// Fault Protection Interrupt: Off
PLLCSR=0x00;
TCCR1A=0x00;
TCCR1B=0x00;
TCCR1C=0x00;
TCCR1D=0x00;
TCCR1E=0x00;
TC1H=0x00;
TCNT1=0x00;
TC1H=0x00;
OCR1A=0x00;
TC1H=0x00;
OCR1B=0x00;
TC1H=0x00;
OCR1C=0x00;
TC1H=0x00;
OCR1D=0x00;
DT1=0x00;
// External Interrupt(s) initialization
// INT0: Off
// INT1: Off
// Interrupt on any change on pins PCINT0-7, 12-15: Off
// Interrupt on any change on pins PCINT8-11: Off
MCUCR=0x00;
GIMSK=0x00;
// Timer(s)/Counter(s) Interrupt(s) initialization
TIMSK=0x00;
// Universal Serial Interface initialization
// Mode: Disabled
// Clock source: Register & Counter=no clk.
// USI Counter Overflow Interrupt: Off
USICR=0x00;
// Analog Comparator initialization
// Analog Comparator: Off
ACSRA=0x80;
// Hysterezis level: 0 mV
ACSRB=0x00;
while (1)
{
PORTA.5=0;
PORTA.6=1;
PORTA.4=0;
for(RESISTANCE = 0; RESISTANCE<=253; RESISTANCE++)
{CommandTheResistor(RESISTANCE);
delay_us(10000);}
};
}