nathanpc

A simple PIC shift register

Mar 21st, 2013
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.12 KB | None | 0 0
  1. /*
  2.  * File:   shift.c
  3.  * Author: Nathan Campos <[email protected]>
  4.  *
  5.  * Created on March 16, 2013, 5:31 PM
  6.  */
  7.  
  8. #include <pic.h>
  9. #include <pic12f683.h>
  10. #include <stdint.h>
  11.  
  12. #define _XTAL_FREQ 4000000
  13.  
  14. // GP0 -> data
  15. // GP1 -> latch
  16. // GP2 -> clock
  17.  
  18. uint8_t sGPIO = 0;
  19.  
  20.  
  21. /*void clear_shift_register() {
  22.     LATCH = 0;
  23.     DATA = 0;
  24.  
  25.     CLOCK = 1;
  26.     CLOCK = 0;
  27.     CLOCK = 1;
  28.     CLOCK = 0;
  29.     CLOCK = 1;
  30.     CLOCK = 0;
  31.     CLOCK = 1;
  32.     CLOCK = 0;
  33.     CLOCK = 1;
  34.     CLOCK = 0;
  35.     CLOCK = 1;
  36.     CLOCK = 0;
  37.     CLOCK = 1;
  38.     CLOCK = 0;
  39.     CLOCK = 1;
  40.     CLOCK = 0;
  41.  
  42.     LATCH = 1;
  43. }*/
  44.  
  45. // GP0 -> data
  46. // GP1 -> latch
  47. // GP2 -> clock
  48. void main(void) {
  49.     TRISIO = 0x00;
  50.     //clear_shift_register();
  51.  
  52.     while (1) {
  53.         sGPIO ^= 0b000001;
  54.         GPIO = sGPIO;
  55.         sGPIO ^= 0b000100;
  56.         GPIO = sGPIO;
  57.  
  58.         sGPIO ^= 0b000000;
  59.         GPIO = sGPIO;
  60.         sGPIO ^= 0b000100;
  61.         GPIO = sGPIO;
  62.  
  63.         sGPIO ^= 0b000001;
  64.         GPIO = sGPIO;
  65.         sGPIO ^= 0b000100;
  66.         GPIO = sGPIO;
  67.  
  68.         sGPIO ^= 0b000001;
  69.         GPIO = sGPIO;
  70.         sGPIO ^= 0b000110;
  71.         GPIO = sGPIO;
  72.  
  73.         __delay_ms(500);
  74.     }
  75. }
Advertisement
Add Comment
Please, Sign In to add comment