pastebin - collaborative debugging

pastebin is a collaborative debugging tool allowing you to share and modify code snippets while chatting on IRC, IM or a message board.

This site is developed to XHTML and CSS2 W3C standards. If you see this paragraph, your browser does not support those standards and you need to upgrade. Visit WaSP for a variety of options.

Advertising: Cheap Flights - Credit Card Consolidation - Car Insurance - Arizona Landscaping
QBasic/QuickBASIC paste-bin - collaborative debugging tool View Help

Posted by Anonymous on Mon 28th Apr 13:01 (modification of post by view diff)
View followups from Anonymous | download | new post

  1. '****************************************************************
  2. '*  Name    : PCCLD106.bas                                      *
  3. '*  Author  : Shannon Wynter (http://fremnet.net)               *
  4. '*  Notice  : Copyright (c) 2008 Shannon Wynter                 *
  5. '*          : All Rights Reserved                               *
  6. '*  Date    : 28/04/2008                                        *
  7. '*  Version : 1.0                                               *
  8. '*  Notes   :                                                   *
  9. '*          :                                                   *
  10. '****************************************************************
  11.  
  12. ' Configure the FUSE options for the compiler
  13. @     device pic16F628A, hs_osc, wdt_off, pwrt_on, lvp_off, protect_off, bod_on, cpd_off, pwrt_off, mclr_off
  14.  
  15. ' Running a 20Mhz clock
  16. DEFINE OSC 20
  17.  
  18. ' Setup the USART
  19. DEFINE HSER_RCSTA 90h     ' Receive register to receiver enabled
  20. DEFINE HSER_TXSTA 20h     ' Transmit register to transmitter enabled
  21. DEFINE HSER_BAUD 2400     ' Set baud rate
  22.  
  23. ' Define some aliases for USART
  24. OERR VAR RCSTA.1 ' Over-run bit
  25. CREN VAR RCSTA.4 ' Continuous receive enable bit
  26. RCIF VAR PIR1.5  ' Received character interrupt flag bit
  27.  
  28. ' Define some aliases for PINS
  29. OVERFLOW VAR PORTB.5  ' Alias pin 11 to indicate an overflow state
  30. HEARTBEAT VAR PORTB.4 ' Alias pin 10 to indicate heartbeat
  31. LDR1 VAR PORTA.0      ' Alias pin 17 for reading LDR1
  32. LDR2 VAR PORTA.1      ' Alias pin 18 for reading LDR2
  33.  
  34. CMCON = 7 ' Turn off the comparators
  35.  
  36. ' Set the direction of pins
  37. INPUT LDR1             ' Set Pin 17 for INPUT
  38. INPUT LDR1             ' Set Pin 18 for INPUT
  39.  
  40. ' Make some storage
  41. myState VAR byte          ' A state holder
  42. pwmLevel VAR BYTE         ' Current dutycycle for the HWPWM
  43. serialByte1 VAR BYTE      ' A serial byte holder
  44. LDR2Value VAR BYTE        ' LDR1 value
  45. LDR1Value var BYTE        ' LDR2 value
  46. heartBeatRate VAR Byte    ' Helps us limit the amount of flashes per second
  47.  
  48. ' Configure the interrupt handler
  49. ON INTERRUPT GOTO interrupt_handler ' Where to go
  50. INTCON = %11000000                  ' Enable the PIE & Global interrupt handler
  51. PIE1.5 = 1                          ' Enable interrupt on USART Receive
  52.  
  53. ' Set up default values
  54. myState = 0        ' Should be off
  55. pwmlevel = 0       ' Should be off
  56. heartBeatRate = 50 ' Beat twice per second
  57.  
  58. ' Turn the heartbeat led on
  59. HIGH HEARTBEAT
  60.  
  61. main_loop:
  62.  
  63. ' Manage the heartbeat
  64. heartBeatRate = heartBeatRate - 1 ' Decrement counter
  65. IF heartBeatRate = 0 THEN
  66.     TOGGLE HEARTBEAT   ' Toggle the heartbeat led
  67.     LOW OVERFLOW       ' Reset the overflow led
  68.    
  69.     ' We throw the LDR readings in here also, not much point in checking light
  70.     ' levels more then twice per second
  71.     POT LDR1, 127, LDR1Value
  72.     POT LDR2, 127, LDR2Value
  73.     ' ToDo: add code to manage logic behind light levels
  74.  
  75.     heartBeatRate = 50 ' Reset the Heartbeat rate
  76. endif
  77.  
  78. ' Manage states
  79. IF mystate = 1 THEN             ' Fading down?
  80.     IF pwmLevel = 0 THEN
  81.         mystate = 0             ' Set state to off(0) if finished fading
  82.     ELSE
  83.         pwmLevel = pwmLevel - 1 ' Continue fading
  84.     ENDIF
  85. ENDIF
  86. IF mystate = 2 THEN             ' Fading up?
  87.     IF pwmLevel = 255 THEN
  88.         mystate = 3             ' Set state to on(3) if finished fading
  89.     ELSE
  90.         pwmLevel = pwmlevel + 1 ' Continue fading
  91.     ENDIF
  92. ENDIF
  93.    
  94. ' Manage the hardware PWM. Should probably completely turn it off/on when in
  95. ' the off/on state to save power
  96. HPWM 1,pwmLevel,32766
  97.  
  98. ' Wait 10 ms (The fade looks best at 10 ms increments)
  99. PAUSE 10
  100. ' Go back through the main program loop
  101. GOTO main_loop
  102.  
  103. ' The interrupt handler
  104. DISABLE ' Disable interrupts while in this code block
  105. interrupt_handler:
  106.     WHILE RCIF                                 ' While there are bytes to be read
  107.         serialByte1 = RCREG                    ' Read a byte
  108.         HSEROUT ["CMD: ", serialByte1, 13, 10] ' Tell the sender what byte was received
  109.         IF serialByte1 = 65 AND myState > 1 THEN myState = 1 ' If A: Check and set state to fade off
  110.         IF serialByte1 = 66 AND myState < 2 THEN myState = 2 ' If B: Check and set state to fade on
  111.         IF serialByte1 = 67 THEN                             ' If C: Print back the LDR values
  112.             HSEROUT ["LDR 1: ", DEC LDR1Value, 13, 10]
  113.             HSEROUT ["LDR 2: ", DEC LDR2Value, 13, 10]
  114.         ENDIF
  115.            
  116.     WEND
  117.  
  118.     ' Clear overruns if present
  119.     IF OERR = 1 THEN
  120.         CREN = 0
  121.         CREN = 1
  122.         HIGH OVERFLOW ' Light the overflow led
  123.     ENDIF
  124.     RESUME
  125. ENABLE

Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:

To highlight particular lines, prefix each line with @@


Remember me
: