Advertisement
Guest User

Untitled

a guest
Apr 26th, 2015
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. #include <avr/io.h>
  2. #include <util/delay.h>
  3.  
  4. #define delay(x) _delay_ms(x)
  5. #define delayMicroseconds(x) _delay_us(x)
  6.  
  7. static void pinMode(int pin, int setting) {
  8. if (pin >= 0 && pin <= 7) {
  9. if (setting > 0) { // Set to OUTPUT
  10. DDRD |= (1<<pin);
  11. } else { // Set to INPUT
  12. DDRD &= ~(1<<pin);
  13. }
  14. } else if (pin >= 8 && pin <= 13) {
  15. if (setting > 0) { // Set to OUTPUT
  16. DDRC |= (1<<pin);
  17. } else { // Set to INPUT
  18. DDRC &= ~(1<<pin);
  19. }
  20. }
  21. return;
  22. }
  23.  
  24. static void analogWrite(int pin, int data) { return; }
  25.  
  26. static int analogRead(int pin) { return 0; }
  27.  
  28. static void digitalWrite(int pin, int data) {
  29. if (pin >= 0 && pin <= 7) {
  30. if (data > 0) { // Set to HIGH
  31. PORTD |= (1<<pin);
  32. } else { // Set to LOW
  33. PORTD &= ~(1<<pin);
  34. }
  35. } else if (pin >= 8 && pin <= 13) {
  36. if (data > 0) { // Set to HIGH
  37. PORTC |= (1<<pin);
  38. } else { // Set to LOW
  39. PORTC &= ~(1<<pin);
  40. }
  41. }
  42. }
  43.  
  44. static int digitalRead(int pin) {
  45. if (pin >= 0 && pin <= 7) {
  46. return PIND & (1<<pin);
  47. } else if (pin >= 8 && pin <= 13) {
  48. return PINC & (1<<pin);
  49. } else {
  50. return 0;
  51. }
  52. }
  53.  
  54. static void serial_init(int baud) {
  55. // Set baud rate
  56. unsigned int bittimer = F_CPU / baud / 16;
  57. UBRR0H = (unsigned char) (bittimer >> 8);
  58. UBRR0L = (unsigned char) bittimer;
  59.  
  60. // Set framing to 8N1
  61. UCSR0C = (3 << UCSZ00);
  62.  
  63. UCSR0B = (1 << RXEN0) | (1 << TXEN0);
  64. return;
  65. }
  66.  
  67. static void serial_write(unsigned char c) {
  68. while ( !(UCSR0A & (1 << UDRE0)) )
  69. ;
  70. UDR0 = c;
  71. return;
  72. }
  73.  
  74. static void serial_print(char *str) {
  75. int i = 0;
  76. while (1) {
  77. serial_write(str[i++])
  78. if (str[i] == '\0') { // NUL termination
  79. break;
  80. }
  81. }
  82. return;
  83. }
  84.  
  85. int main(void) {
  86. setup();
  87.  
  88. while(1)
  89. loop();
  90.  
  91. return 0;
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement