|

楼主 |
发表于 2009-11-1 11:47:45
|
显示全部楼层
原帖由 龙虾 于 2009-11-1 10:44 发表 
如何防止铜线挂在框架边上?
基本靠手...
程序, 用winavr
比较乱, 见笑了~
#include <stdlib.h>
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/signal.h>
#include <avr/pgmspace.h>
#include "util/delay.h"
#include "avr/sleep.h"
#include "avr/wdt.h"
#ifndef cbi
#define cbi(x, i) ((x) &= ~( 1<<(i) ))
#endif
#ifndef sbi
#define sbi(x, i) ((x) |= ( 1<<(i) ))
#endif
#ifndef bit_set
#define bit_set(x, i) ((x) & ( 1<<(i) ) )
#endif
volatile int volt, r;
unsigned char mask[] PROGMEM = { 0xd7, 0x11, 0xcd, 0x5d, 0x1b, 0x5e, 0xde, 0x15, 0xdf, 0x5f };
#define delayms(ms) _delay_ms(ms)
int DISPLAY(void);
SIGNAL (SIG_OVERFLOW0);
int main(void);
int DISPLAY() {
int i, j;
unsigned int k;
unsigned char data, pp;
k = volt;
pp = 2;
for( j = 0; j < 3 ; j++ ) {
data = pgm_read_byte( &(mask[k%10] ));
k /= 10;
if( pp & (1<<j) )
sbi(data, 5);
for( i = 0; i < 8; i++ ) {
cbi( PORTB, 2);
if(data & 0x80)
sbi( PORTB, 0);
else
cbi( PORTB, 0);
data <<= 1;
sbi( PORTB, 2);
_delay_us(1);
}
sbi( PORTB, 0);
cbi( PORTB, 1);
_delay_us(1);
sbi( PORTB, 1);
cbi(PORTD, j+5);
_delay_us(300);
sbi(PORTD, j+5);
}
return 0;
}
SIGNAL (SIG_INTERRUPT0 ) {
volt++;
if( r > 0 )
r--;
}
SIGNAL (SIG_OVERFLOW0) {
static int count = 0, count2 = 0;
count++;
count2++;
if ( r > 0 )
sbi( PORTD, 3 );
else
cbi( PORTD, 3 );
if ( count > 100 ) {
count = 0;
}
TCNT0 = 132;
}
int main() {
DDRD = ~0;
DDRC = 0b11111100;
DDRB = ~0;
PORTD = ~0;
PORTC = 0b00000011;
PORTB = ~0;
TCNT0 = 132;
TCCR0B = 0x1;
cbi( DDRD, 2 );
cbi( PORTD, 2 );
sbi( TIMSK0, TOIE0);
sbi( EICRA, ISC01 );
sbi( EICRA, ISC00 );
sbi( EIMSK, INT0 );
sei();
volt = 0;
while(1) {
if( !bit_set( PINC, 1 ) && r == 0 ) {
_delay_us(10);
if( !bit_set( PINC, 1 ) ) {
r = 100;
}
}
if( !bit_set( PINC, 0 ) && r == 0 ) {
_delay_us(10);
if( !bit_set( PINC, 0 ) ) {
r = 10;
}
}
DISPLAY();
}
} |
|