Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Jan 17th, 2013  |  syntax: C  |  size: 1.51 KB  |  views: 37  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
This paste has a previous version, view the difference. Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #include<util/delay.h>
  2. #include<avr/io.h>
  3. #include"defines.h"
  4. void control_write(unsigned char control)
  5. {
  6.     GLCD_DATA_DDR = 0XFF;
  7.         GLCD_CTRL_PORT &= ~(1<<GLCD_CTRL_E);
  8.     GLCD_CTRL_PORT &= ~(1<<GLCD_CTRL_RW);
  9.         GLCD_CTRL_PORT |= (1<<GLCD_CTRL_CS0);
  10.         GLCD_CTRL_PORT &= ~(1<<GLCD_CTRL_RS);
  11.         asm volatile ("nop"); asm volatile ("nop");
  12.         asm volatile ("nop"); asm volatile ("nop");
  13.         GLCD_CTRL_PORT |= (1<<GLCD_CTRL_E);
  14.         asm volatile ("nop"); asm volatile ("nop");
  15.         GLCD_DATA_PORT = 0x3e;
  16.     GLCD_CTRL_PORT |= (1<<GLCD_CTRL_RW);
  17.         asm volatile ("nop"); asm volatile ("nop");
  18. }
  19. unsigned char control_read()
  20. {
  21.         unsigned char control;
  22.         GLCD_DATA_DDR = 0X00;
  23.         GLCD_CTRL_PORT &= ~(1<<GLCD_CTRL_E);
  24.     GLCD_CTRL_PORT |= (1<<GLCD_CTRL_RW);
  25.         GLCD_CTRL_PORT |= (1<<GLCD_CTRL_CS0);
  26.         GLCD_CTRL_PORT &= ~(1<<GLCD_CTRL_RS);
  27.         asm volatile ("nop"); asm volatile ("nop");
  28.         asm volatile ("nop"); asm volatile ("nop");
  29.         GLCD_CTRL_PORT |= (1<<GLCD_CTRL_E);
  30.         asm volatile ("nop"); asm volatile ("nop");
  31.         control = GLCD_DATA_PIN;
  32.     GLCD_CTRL_PORT &= ~(1<<GLCD_CTRL_RW);
  33.         asm volatile ("nop"); asm volatile ("nop");
  34.         return control;
  35. }
  36.  
  37. int main(void){
  38.         unsigned char control;
  39.     _delay_ms(100);
  40.         DDRB = 0xFF;
  41.         GLCD_CTRL_DDR = 0XFF;
  42.         GLCD_CTRL_PORT &= ~(1<<GLCD_CTRL_RESET);
  43.     while(1){
  44.         //CONTROL WRITE
  45.         control_write(GLCD_ON_CTRL);
  46.         //CONTROL READ
  47.         control = control_read();
  48.         PORTB |= (1<<1);
  49.         if(control & GLCD_STATUS_BUSY)
  50.             PORTB |= (1<<0);
  51.         }
  52.         return 0;
  53. }