U23 2007/Evil Solutions/dimmer.c

From C4 Wiki
< U23 2007‎ | Evil Solutions
Revision as of 19:24, 4 June 2007 by Evil Operator (talk | contribs) (New page: <pre> #include <avr/io.h> void ins_schieb (char); void delay (uint8_t); uint8_t is_Set (uint8_t, char); int main(void) { DDRA = 0xFF; // Set OE PORTA = 0x08 ; ins_schieb(0); dela...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
#include <avr/io.h>

void ins_schieb (char);
void delay (uint8_t);
uint8_t is_Set (uint8_t, char);

int main(void) {

	DDRA = 0xFF;
	// Set OE
	PORTA = 0x08 ;

	ins_schieb(0);

	delay(128);

	uint8_t a, b, c;


	while (1) {


		// aufblenden
		for (b = 0 ; b < 20 ; b++) {
			for (c = 0; c < 20 ; c++) {
				// anmachen
				for (a = 0; a <= b ; a++) {
					ins_schieb(0x01);
				}
				for (a = 20-b; a > 0; a--) {
					ins_schieb(0x80);
				}
			
			}

		}

		// abblenden
		for (b = 20 ; b > 0 ; b--) {
			for (c = 0; c < 20 ; c++) {
				// anmachen
				for (a = 0; a <= b ; a++) {
					ins_schieb(0x01);
				}
				for (a = 20-b; a > 0; a--) {
					ins_schieb(0x80);
				}
			
			}

		}

	}

	return 0;
}

void ins_schieb ( char eingabe) {

	uint16_t i;
	for ( i = 0 ; i <= 16 ; i++) {
		// Data

		if ( i % 2) {
			if ( is_Set( ((int) i/2), eingabe )){
				PORTA |= (1 << 1);
			}else {
				PORTA &= ~ (1 << 1);
			}
		}

		// Clock
		if ( i % 2 ) {
			PORTA |= (1 << 2 );
		} else {
			PORTA &= ~ (1 << 2 );
		}
	}

	// Set and unset Strobe
	PORTA |= (1 << 0 ) ;
	PORTA &= ~ (1 << 0 ) ;
}

uint8_t is_Set (uint8_t bit, char eingabe) {

	uint8_t op2 = eingabe & (~ (1 << bit));
	uint8_t erg = eingabe ^ op2; 

	if (erg > 0)
		return 1;
	return 0;
}

void delay(uint8_t adelay){
	uint16_t b;
	uint16_t a;

	for (a = 0 ; a < adelay; a++)
		for (b = 0; b < 0xFF ; b++) {
			PORTB = 0x00;
			/* nix */
		}
}