Subversion Repositories svnkaklik

Rev

Rev 182 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log

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