Subversion Repositories svnkaklik

Rev

Rev 410 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log

Rev Author Line No. Line
134 kaklik 1
/*********************************************
2
* vim: set sw=8 ts=8 si :
3
* Author: Guido Socher, Copyright: GPL 
4
* This program is to test the led connected to
5
* PC5. 
6
* See http://linuxfocus.org/English/November2004/
7
* for details.
8
* Chip type           : ATMEGA8
9
* Clock frequency     : Internal clock 1 Mhz (factory default)
10
*********************************************/
11
#include <avr/io.h>
12
#include <inttypes.h>
484 kaklik 13
#define F_CPU 1000000UL  // 1 MHz
134 kaklik 14
#include <avr/delay.h>
15
 
16
 
17
/* compatibilty macros for old style */
18
#ifndef cbi
19
#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
20
#endif
21
 
22
#ifndef sbi
23
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
24
#endif
25
 
26
 
27
void delay_ms(unsigned int ms)
28
/* delay for a minimum of <ms> */
29
{
30
	// we use a calibrated macro. This is more
31
	// accurate and not so much compiler dependent
32
	// as self made code.
33
	while(ms){
34
		_delay_ms(0.96);
35
		ms--;
36
	}
37
}
38
 
39
 
40
/* new style */
41
int main(void)
42
{
43
          /* INITIALIZE */
44
          /* enable PC5 as output */
45
          DDRC|= (1<<DDC5);
46
 
47
          /* PC5 is 5 (see file include/avr/iom8.h) and 1<<PC5 is 00100000 
48
	   * This can also be written as _BV(PC5)*/
49
          while (1) {
50
                      /* led on, pin=0 */
51
                      PORTC &= ~(1<<PC5);
52
                      delay_ms(500);
53
                      /* set output to 5V, LED off */
54
                      PORTC|= (1<<PC5);
55
                      delay_ms(500);
56
          }
57
	  return(0);
58
}
59
 
60
 
61
// // old style now depricated:
62
// int main(void)
63
// {
64
// 	// enable  PC5 as output 
65
// 	sbi(DDRC,PC5);
66
// 	while (1) {
67
// 		// led on, pin=0 
68
// 		cbi(PORTC,PC5);
69
// 		delay_ms(500);
70
// 		// set output to 5V, LED off 
71
// 		sbi(PORTC,PC5);
72
// 		delay_ms(500);
73
// 	}
74
// 	return(0);
75
// }
76
// // end of old style