Advertisement
Guest User

solarwind

a guest
Mar 5th, 2009
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.77 KB | None | 0 0
  1. #include "main.h"
  2. #include "delay.h"
  3. #include "AS1107_driver.h"
  4.  
  5. //Strobe the CLOCK line
  6. void AS1107_clock() {
  7.     CLOCK = 1;
  8.     Nop();
  9.     CLOCK = 0;
  10.     Nop();
  11. }
  12.  
  13. //Strobe the LATCH line
  14. void AS1107_latch() {
  15.     LATCH = 1;
  16.     Nop();
  17.     LATCH = 0;
  18.     Nop();
  19. }
  20.  
  21. void AS1107_send_data(byte address, byte data) {
  22.     byte c;
  23.     //The first 4 bits are not used
  24.     DATA = 0;
  25.     AS1107_clock();
  26.     AS1107_clock();
  27.     AS1107_clock();
  28.     AS1107_clock();
  29.    
  30.     //Clock in the next 4 bits (register address)
  31.     for(c = 4; c > 0; c--) {
  32.         DATA = (address >> c) & 1;
  33.         AS1107_clock();
  34.     }
  35.  
  36.     //Clock in the next 8 bits (register data)
  37.     for(c = 8; c > 0; c--) {
  38.         DATA = (data >> c) & 1;
  39.         AS1107_clock();
  40.     }
  41.  
  42.     //Latch in the data
  43.     AS1107_latch();
  44.    
  45. }
  46.  
  47. void AS1107_init() {
  48.     AS1107_latch();
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement