Advertisement
whitecode12

PoliceLED assembly

Aug 15th, 2024
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
ASM (NASM) 3.17 KB | Source Code | 0 0
  1. ; Police LED Light Bar
  2. ; Author: Your Name
  3. ; Date: 15.8.2024
  4.  
  5. .data
  6.     patternCount    equ 30
  7.     LED1            equ 3
  8.     LED2            equ 4
  9.     LED3            equ 5
  10.     LED4            equ 6
  11.     LED5            equ 7
  12.     LED6            equ 8
  13.     LED7            equ 9
  14.     LED8            equ 10
  15.     LED9            equ 11
  16.     LED10           equ 12
  17.     buttonPin       equ 2
  18.     lastButtonTime  dq 0
  19.     pattern         dd 0
  20.  
  21. .code
  22. setup:
  23.     ; Set LED pins as output
  24.     mov rcx, LED1
  25.     call pinMode
  26.     mov rcx, LED2
  27.     call pinMode
  28.     mov rcx, LED3
  29.     call pinMode
  30.     mov rcx, LED4
  31.     call pinMode
  32.     mov rcx, LED5
  33.     call pinMode
  34.     mov rcx, LED6
  35.     call pinMode
  36.     mov rcx, LED7
  37.     call pinMode
  38.     mov rcx, LED8
  39.     call pinMode
  40.     mov rcx, LED9
  41.     call pinMode
  42.     mov rcx, LED10
  43.     call pinMode
  44.  
  45.     ; Set button pin as input
  46.     mov rcx, buttonPin
  47.     mov rdx, INPUT
  48.     call pinMode
  49.  
  50.     ret
  51.  
  52. loop:
  53.     ; Check if button is pressed and debounce
  54.     mov rcx, buttonPin
  55.     call digitalRead
  56.     test rax, rax
  57.     jz no_button_press
  58.  
  59.     call millis
  60.     mov rbx, [lastButtonTime]
  61.     sub rax, rbx
  62.     cmp rax, 100
  63.     jle no_button_press
  64.  
  65.     ; Update last button press time
  66.     call millis
  67.     mov [lastButtonTime], rax
  68.  
  69.     ; Increment pattern
  70.     mov eax, [pattern]
  71.     inc eax
  72.     xor edx, edx
  73.     mov ecx, patternCount
  74.     div ecx
  75.     mov [pattern], edx
  76.  
  77. no_button_press:
  78.     ; Switch based on pattern
  79.     mov eax, [pattern]
  80.     cmp eax, 1
  81.     je pattern1
  82.     cmp eax, 2
  83.     je pattern2
  84.     cmp eax, 3
  85.     je pattern3
  86.     jmp loop
  87.  
  88. pattern1:
  89.     ; LED1-5 on
  90.     mov rcx, LED1
  91.     mov rdx, HIGH
  92.     call digitalWrite
  93.     mov rcx, LED2
  94.     call digitalWrite
  95.     mov rcx, LED3
  96.     call digitalWrite
  97.     mov rcx, LED4
  98.     call digitalWrite
  99.     mov rcx, LED5
  100.     call digitalWrite
  101.  
  102.     mov rcx, 50
  103.     call delay
  104.  
  105.     ; LED1-5 off
  106.     mov rcx, LED1
  107.     mov rdx, LOW
  108.     call digitalWrite
  109.     mov rcx, LED2
  110.     call digitalWrite
  111.     mov rcx, LED3
  112.     call digitalWrite
  113.     mov rcx, LED4
  114.     call digitalWrite
  115.     mov rcx, LED5
  116.     call digitalWrite
  117.  
  118.     mov rcx, 50
  119.     call delay
  120.  
  121.     ; Repeat two more times...
  122.  
  123.     ; LED6-10 on
  124.     mov rcx, LED6
  125.     mov rdx, HIGH
  126.     call digitalWrite
  127.     mov rcx, LED7
  128.     call digitalWrite
  129.     mov rcx, LED8
  130.     call digitalWrite
  131.     mov rcx, LED9
  132.     call digitalWrite
  133.     mov rcx, LED10
  134.     call digitalWrite
  135.  
  136.     mov rcx, 50
  137.     call delay
  138.  
  139.     ; LED6-10 off
  140.     mov rcx, LED6
  141.     mov rdx, LOW
  142.     call digitalWrite
  143.     mov rcx, LED7
  144.     call digitalWrite
  145.     mov rcx, LED8
  146.     call digitalWrite
  147.     mov rcx, LED9
  148.     call digitalWrite
  149.     mov rcx, LED10
  150.     call digitalWrite
  151.  
  152.     mov rcx, 50
  153.     call delay
  154.  
  155.     ; Repeat two more times...
  156.  
  157.     jmp loop
  158.  
  159. pattern2:
  160.     ; Similar to pattern1, but with different timing
  161.  
  162. pattern3:
  163.     mov rcx, LED5
  164.     mov rdx, HIGH
  165.     call digitalWrite
  166.  
  167.     ; Continue with the rest of pattern3...
  168.  
  169.     jmp loop
  170.  
  171. ; External function declarations (Arduino-like functions)
  172. extern pinMode
  173. extern digitalWrite
  174. extern digitalRead
  175. extern millis
  176. extern delay
  177.  
  178. end
  179.  
  180.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement