Guest User

Untitled

a guest
Aug 2nd, 2018
351
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 21.04 KB | None | 0 0
  1. .include "m328Pdef.inc"
  2. .equ fclk = 16000000 ; frequencia do clock do processador
  3.  
  4. ; register usage
  5. .def temp = R16 ; variável temporária
  6.  
  7. ; Configuração da interface do arduíno com o display 1602
  8. .equ lcd_D7_port = PORTD ; lcd D7 connection
  9. .equ lcd_D7_bit = PORTD7
  10. .equ lcd_D7_ddr = DDRD
  11.  
  12. .equ lcd_D6_port = PORTD ; lcd D6 connection
  13. .equ lcd_D6_bit = PORTD6
  14. .equ lcd_D6_ddr = DDRD
  15.  
  16. .equ lcd_D5_port = PORTD ; lcd D5 connection
  17. .equ lcd_D5_bit = PORTD5
  18. .equ lcd_D5_ddr = DDRD
  19.  
  20. .equ lcd_D4_port = PORTD ; lcd D4 connection
  21. .equ lcd_D4_bit = PORTD4
  22. .equ lcd_D4_ddr = DDRD
  23.  
  24. .equ lcd_E_port = PORTB ; lcd Enable pin
  25. .equ lcd_E_bit = PORTB1
  26. .equ lcd_E_ddr = DDRB
  27.  
  28. .equ lcd_RS_port = PORTB ; lcd Register Select pin
  29. .equ lcd_RS_bit = PORTB0
  30. .equ lcd_RS_ddr = DDRB
  31.  
  32. ; LCD module information
  33. .equ lcd_LineOne = 0x00 ; posição de início da linha 1 no display
  34. .equ lcd_LineTwo = 0x40 ; posição de início da linha 2 no display
  35.  
  36. ; LCD instructions
  37. .equ lcd_Clear = 0b00000001 ; substitui todos os caracteres do display pelo ASCII "espaço"
  38. .equ lcd_Home = 0b00000010 ; retorna o curso para a primeira posição da primeira linha
  39. .equ lcd_EntryMode = 0b00000110 ; muda o cursor da esquerda para a direita em operações de read/write
  40. .equ lcd_DisplayOff = 0b00001000 ; desliga o display
  41. .equ lcd_DisplayOn = 0b00001100 ; liga o dislay
  42. .equ lcd_FunctionReset = 0b00110000 ; reincializa o display LCD
  43. .equ lcd_FunctionSet4bit = 0b00101000 ; 4-bit de dados, display de duas linhas, fonte 5 x 7
  44. .equ lcd_SetCursor = 0b10000000 ; define a posição do cursor
  45.  
  46. ;REgistradores utilizados pelo código do Keypad
  47. .def lb = R25
  48. .def hb = R24
  49. .def contagem=r23
  50. .def debounce=r22
  51. .def temp2=r21
  52. .def temp3=r18
  53. .def dbl=r20
  54. .def dbh=r19
  55.  
  56.  
  57. ;PARA MULTIPLICAR
  58. .DEF rm1 = R0 ; Número binário a ser multiplicado (8 Bit)
  59. .DEF rmh = R1 ; Armazém intermediário
  60. .DEF rm2 = R2 ; Número binário com que o primeiro será multiplicado (8 Bit)
  61. .DEF rel = R3 ; Resultado, LSB (16 Bit)
  62. .DEF reh = R4 ; Resultado, MSB
  63. .DEF rmp = R17 ; Registrador multi propósitos para carregamento
  64.  
  65.  
  66. ; ****************************** Interrupção de Reset *******************************
  67. .org 0x0000
  68. jmp start ; pula para start quando a interrupção de reset é disparada.
  69.  
  70. .org INT_VECTORS_SIZE;Início do programa
  71.  
  72.  
  73. ; ****************************** Código do programa principal **************************
  74. start:
  75.  
  76. ; inicializando os apontadores de pilha para trabalharem com as faixas de memória do processador
  77. ldi temp,low(RAMEND)
  78. out SPL,temp
  79. ldi temp,high(RAMEND)
  80. out SPH,temp
  81.  
  82. ; Configurando os pinos do processador a serem utilizados com o display
  83. sbi lcd_D7_ddr, lcd_D7_bit ; 4 data lines - output
  84. sbi lcd_D6_ddr, lcd_D6_bit
  85. sbi lcd_D5_ddr, lcd_D5_bit
  86. sbi lcd_D4_ddr, lcd_D4_bit
  87.  
  88. ; Configurando os pinos do processador a serem utilizados como barramento de controle do display
  89. sbi lcd_E_ddr, lcd_E_bit ; E line - output
  90. sbi lcd_RS_ddr, lcd_RS_bit ; RS line - output
  91.  
  92. ; Inicializando o display
  93. call lcd_init_4d ; initialize the LCD display for a 4-bit interface
  94.  
  95. ;Inicializando o número a ser modificado pelo keypad
  96. ldi contagem, 0
  97. ldi debounce, 0
  98.  
  99. ;
  100. ;
  101. ;
  102. ;============================================Área que deverá ser alterada no trabalho==============================================================
  103. ; Exibindo a primeira linha de informação no display
  104.  
  105. ;Primeira string, início na posição de memória 0x040B
  106. ldi XH, 0x04
  107. ldi XL, 0x0B
  108. ldi temp, 'A'
  109. st X+, temp;o incremento de X está sendo feito automatiamente com X+
  110. ldi temp, 'R'
  111. st X+, temp
  112. ldi temp, 'E'
  113. st X+, temp
  114. ldi temp, 'A'
  115. st X+, temp
  116. ldi temp, ' '
  117. st X+, temp
  118. ldi temp, 'C'
  119. st X+, temp
  120. ldi temp, 'I'
  121. st X+, temp
  122. ldi temp, 'R'
  123. st X+, temp
  124. ldi temp, 'C'
  125. st X+, temp
  126. ldi temp, 0;o zero indica o fim da string
  127. st X+, temp
  128.  
  129.  
  130. ldi XH, 0x04
  131. ldi XL, 0x0B
  132. ldi temp, lcd_LineOne ; estabece em qual linha a informação será exibida
  133. call lcd_write_string_4d ; chama a subrotina que imprime na tela do display
  134.  
  135. ; display the second line of information
  136. ;String two, start in 0x0418
  137. ldi temp, 'D' ;DIGITE RAIO PARA O CALCULO, DE 1 A 5
  138. st X+, temp
  139. ldi temp, 'I'
  140. st X+, temp
  141. ldi temp, 'G'
  142. st X+, temp
  143. ldi temp, 'T'
  144. st X+, temp
  145. ldi temp, ' '
  146. st X+, temp
  147. ldi temp, 'R'
  148. st X+, temp
  149. ldi temp, ':'
  150. st X+, temp
  151. ldi temp, ' '
  152. st X+, temp
  153.  
  154.  
  155.  
  156. ;************Keypad code
  157.  
  158.  
  159. LDI temp, 0b0100_0000 ;selecionar entrada A0
  160. STS ADMUX, temp
  161.  
  162. inicio:
  163. ;Ajustando endereço de memória para armazenar a tecla pressionada. Só tem valor real para a segunda tecla pressionada
  164. ldi XH, 0x04
  165. ldi XL, 0x20
  166.  
  167. LDI temp, 0b1100_0010 ;Ativar conversão AD e o prescaler
  168. sts ADCSRA, TEMP
  169.  
  170.  
  171. AGUARDAR_CONVERSAO:
  172. LDS temp, ADCSRA ;lendo status do processo de conversão
  173. ANDI temp,0b00010000 ;checando se a conversão já terminou
  174. BREQ AGUARDAR_CONVERSAO ;senão, volta para aguardar_conversao(esperar)
  175. LDS ZL,ADCL ;ler o byte inferior da conversão (16bits)
  176. LDS ZH,ADCH ;ler o byte superior da conversão (16bits)
  177. ldi temp, 200 ; delay para diminuir o debounce
  178. call delay1mS
  179.  
  180.  
  181. comparacoes:
  182. ;Comparações para os diversos botões
  183. ;Direita
  184. ldi lb, 0b01100100
  185. ldi hb, 0b00000000
  186. cp ZL, lb
  187. cpc ZH, hb
  188. brcs direita
  189. ;Cima
  190. ldi lb, 0b11001000
  191. ldi hb, 0b00000000
  192. cp ZL, lb
  193. cpc ZH, hb
  194. brcs cima
  195. ;baixo
  196. ldi lb, 0b10010000
  197. ldi hb, 0b00000001
  198. cp ZL, lb
  199. cpc ZH, hb
  200. brcs baixo
  201. ;Esquerda
  202. ldi lb, 0b01011000
  203. ldi hb, 0b00000010
  204. cp ZL, lb
  205. cpc ZH, hb
  206. brcs esquerda
  207. ;select
  208. ldi lb, 0b00100000
  209. ldi hb, 0b00000011
  210. cp ZL, lb
  211. cpc ZH, hb
  212. brcs select
  213. ldi debounce, 0
  214.  
  215. retorna_inicio:
  216. RJMP inicio
  217.  
  218.  
  219. ;Alterar apenas a partir daqui
  220. ;O trecho abaixo exibe qual dos botões Esquerda, Direita, Cima e Baixo foi apertado
  221. direita:;NAO PRECISOU UTILIZAR PQ SÓ PRECISA DE UMA VARIAVEL QUE É O RAIO
  222. cpi debounce, 'd'
  223. breq retorna_inicio
  224. ldi debounce, 'd'
  225. ldi temp, '*'
  226. st X+, temp
  227. rjmp escreve_linha_2
  228. esquerda:;NAO PRECISOU UTILIZAR PQ SÓ PRECISA DE UMA VARIAVEL QUE É O RAIO
  229. cpi debounce, 'e'
  230. breq retorna_inicio
  231. ldi debounce, 'e'
  232. ldi temp, '*'
  233. st X+, temp
  234. rjmp escreve_linha_2
  235. cima:
  236. cpi debounce, 'c'
  237. breq retorna_inicio
  238. ldi debounce, 'c'
  239. ;bloqueio de incremento > 5
  240. cpi contagem, 9
  241. breq retorna_inicio
  242. ;fim de bloqueio de decremento >5
  243. inc contagem
  244. st X+, contagem
  245. rcall converte_ascii_2d
  246. rjmp escreve_linha_2
  247. baixo:
  248. cpi debounce, 'b'
  249. breq retorna_inicio
  250. ldi debounce, 'b'
  251. ;bloqueio de incremento < 0
  252. cpi contagem, 0
  253. breq retorna_inicio
  254. ;fim de bloqueio de incremento < 0
  255. dec contagem
  256. ;Fim de Convertendo número para ASCII
  257. st X+, contagem
  258. rcall converte_ascii_2d
  259. rjmp escreve_linha_2
  260. select: ;ONDE É FEITO O CALCULO
  261. ;call lcd_Clear
  262. cpi debounce, 's'
  263. breq retorna_inicio
  264. ldi debounce, 's'
  265. ldi temp, '*'
  266.  
  267.  
  268. mov rm2, contagem;CALCULO DO R AO QUADRADO
  269. mov rm1, contagem
  270. MULT8:
  271. ; Zera valores de início
  272. clr rmh ; zera armazém intermediário
  273. clr rel ; zera registradores de resultado
  274. clr reh
  275. ; Aqui iniciamos o ciclo de multiplicação
  276. ; Aqui iniciamos o ciclo de multiplicação
  277. MULT8a:
  278. ;
  279. ; Passo 1: Rotaciona o bit mais baixo do número 2 para a flag de carry (divide por 2, rotaciona um zero no bit 7)
  280. ;
  281. clc ; zera carry
  282. ror rm2 ; bit 0 vai para o carry, bit 1 a 7 vão uma posição para direita, carry vai para o bit 7
  283. ;
  284. ; Passo 2: Decisão dependendo se foi 0 ou 1 que foi rotacionado para o carry
  285. ;
  286. brcc MULT8b ; pula por cima da adição, se o carry for 0
  287. ;
  288. ; Passo 3: Soma 16 bits em rmh:rml ao resultado, com estouro do LSB para o MSB
  289. ;
  290. add rel,rm1 ; soma o LSB de rm1 ao resultado
  291. adc reh,rmh ; soma carry e MSB de rm1
  292. ;
  293. MULT8b:
  294. ;
  295. ; Passo 4: Multiplicar rmh:rm 1 por 2 (16 bits, desvio à esquerda)
  296. ;
  297. clc ; zera carry (clear carry bit)
  298. rol rm1 ; rotaciona o LSB à esquerda (multiplica por 2)
  299. rol rmh ; rotaciona o carry para o MSB e o MSB uma casa à esquerda
  300. ;
  301. ; Passo 5: Checa se há ainda números 1 no binário 2, se sim, continua multiplicando
  302. ;
  303. tst rm2 ; todos os bits zero?
  304. brne MULT8a ; se não, vá para o loop
  305. ;
  306. ; Fim da multiplicação r ao quadrado, resultado em reh:rel
  307. mov contagem, rel
  308.  
  309. ; multiplicar por 3 (PI)...
  310. mov rm1, rel
  311. ldi rmp,0b00000011
  312. mov rm2,rmp ; para o segundo registrador
  313. MULT9:
  314. ;
  315. ; Zera valores de início
  316. clr rmh ; zera armazém intermediário
  317. clr rel ; zera registradores de resultado
  318. clr reh
  319. ;
  320. ; Aqui iniciamos o ciclo de multiplicação
  321. ; Aqui iniciamos o ciclo de multiplicação
  322. ;
  323. MULT9a:
  324. ;
  325. ; Passo 1: Rotaciona o bit mais baixo do número 2 para a flag de carry (divide por 2, rotaciona um zero no bit 7)
  326. ;
  327. clc ; zera carry
  328. ror rm2 ; bit 0 vai para o carry, bit 1 a 7 vão uma posição para direita, carry vai para o bit 7
  329. ;
  330. ; Passo 2: Decisão dependendo se foi 0 ou 1 que foi rotacionado para o carry
  331. ;
  332. brcc MULT9b ; pula por cima da adição, se o carry for 0
  333. ;
  334. ; Passo 3: Soma 16 bits em rmh:rml ao resultado, com estouro do LSB para o MSB
  335. ;
  336. add rel,rm1 ; soma o LSB de rm1 ao resultado
  337. adc reh,rmh ; soma carry e MSB de rm1
  338. ;
  339. MULT9b:
  340. ;
  341. ; Passo 4: Multiplicar rmh:rm 1 por 2 (16 bits, desvio à esquerda)
  342. ;
  343. clc ; zera carry (clear carry bit)
  344. rol rm1 ; rotaciona o LSB à esquerda (multiplica por 2)
  345. rol rmh ; rotaciona o carry para o MSB e o MSB uma casa à esquerda
  346. ;
  347. ; Passo 5: Checa se há ainda números 1 no binário 2, se sim, continua multiplicando
  348. ;
  349. tst rm2 ; todos os bits zero?
  350. brne MULT9a ; se não, vá para o loop
  351. ;
  352. ; Fim da multiplicação r ao quadrado, resultado em reh:rel
  353.  
  354.  
  355.  
  356. st X+, rel;resultado aproximado
  357. rcall converte_ascii_2d
  358. rjmp escreve_linha_2
  359.  
  360.  
  361. ; Rotina que converte um valor na memória na posição X-1 em ASCII (para dois dígitos)
  362. converte_ascii_2d: ld temp, -X
  363. mov temp2, temp
  364. clr temp3
  365. testa_maior: cpi temp2, 10
  366. brmi menorq10
  367. subi temp2, 10
  368. inc temp3
  369. jmp testa_maior
  370. menorq10: cpi temp3, 0
  371. breq so_unidades
  372. ldi temp, 48
  373. add temp, temp3
  374. st X+, temp
  375. so_unidades: ldi temp, 48
  376. add temp, temp2
  377. st X+, temp
  378. ret
  379.  
  380. escreve_linha_2:
  381.  
  382. ldi temp, ' ' ;espaço em branco
  383. st X+, temp
  384. ldi temp, 0 ;o zero indica o fim da string
  385. st X, temp
  386. ldi XH, 0x04 ;posição de memória onde começa a segunda string
  387. ldi XL, 0x19
  388. ldi temp, lcd_LineTwo ; estabece em qual linha a informação será exibida
  389. call lcd_write_string_4d ; chama a subrotina que imprime na tela do display
  390. rjmp retorna_inicio
  391. ; ===============================Fim da Área que deverá ser alterada no trabalho =======================================================
  392. here:
  393. rjmp here
  394.  
  395. ; ****************************** Fim do programa principal *******************
  396.  
  397. ; ============================== 4-bit LCD Subroutines ======================
  398. ; Purpose: initialize the LCD module for a 4-bit data interface
  399. lcd_init_4d:
  400. ; Power-up delay
  401. ldi temp, 100 ; initial 40 mSec delay
  402. call delayTx1mS
  403.  
  404. ; Set up the RS and E lines for the 'lcd_write_4' subroutine.
  405. cbi lcd_RS_port, lcd_RS_bit ; select the Instruction Register (RS low)
  406. cbi lcd_E_port, lcd_E_bit ; make sure E is initially low
  407.  
  408. ; Reset the LCD controller.
  409. ldi temp, lcd_FunctionReset ; first part of reset sequence
  410. call lcd_write_4
  411. ldi temp, 10 ; 4.1 mS delay (min)
  412. call delayTx1mS
  413.  
  414. ldi temp, lcd_FunctionReset ; second part of reset sequence
  415. call lcd_write_4
  416. ldi temp, 200 ; 100 uS delay (min)
  417. call delayTx1uS
  418.  
  419. ldi temp, lcd_FunctionReset ; third part of reset sequence
  420. call lcd_write_4
  421. ldi temp, 200 ; this delay is omitted in the data sheet
  422. call delayTx1uS
  423.  
  424. ; Preliminary Function Set instruction - used only to set the 4-bit mode.
  425. ; The number of lines or the font cannot be set at this time since the controller is still in the
  426. ; 8-bit mode, but the data transfer mode can be changed since this parameter is determined by one
  427. ; of the upper four bits of the instruction.
  428. ldi temp, lcd_FunctionSet4bit ; set 4-bit mode
  429. call lcd_write_4
  430. ldi temp, 80 ; 40 uS delay (min)
  431. call delayTx1uS
  432.  
  433. ; Function Set instruction
  434. ldi temp, lcd_FunctionSet4bit ; set mode, lines, and font
  435. call lcd_write_instruction_4d
  436. ldi temp, 80 ; 40 uS delay (min)
  437. call delayTx1uS
  438.  
  439. ; The next three instructions are specified in the data sheet as part of the initialization routine,
  440. ; so it is a good idea (but probably not necessary) to do them just as specified and then redo them
  441. ; later if the application requires a different configuration.
  442.  
  443. ; Display On/Off Control instruction
  444. ldi temp, lcd_DisplayOff ; turn display OFF
  445. call lcd_write_instruction_4d
  446. ldi temp, 80 ; 40 uS delay (min)
  447. call delayTx1uS
  448.  
  449. ; Clear Display instruction
  450. ldi temp, lcd_Clear ; clear display RAM
  451. call lcd_write_instruction_4d
  452. ldi temp, 4 ; 1.64 mS delay (min)
  453. call delayTx1mS
  454.  
  455. ; Entry Mode Set instruction
  456. ldi temp, lcd_EntryMode ; set desired shift characteristics
  457. call lcd_write_instruction_4d
  458. ldi temp, 80 ; 40 uS delay (min)
  459. call delayTx1uS
  460.  
  461. ; This is the end of the LCD controller initialization as specified in the data sheet, but the display
  462. ; has been left in the OFF condition. This is a good time to turn the display back ON.
  463.  
  464. ; Display On/Off Control instruction
  465. ldi temp, lcd_DisplayOn ; turn the display ON
  466. call lcd_write_instruction_4d
  467. ldi temp, 80 ; 40 uS delay (min)
  468. call delayTx1uS
  469. ret
  470.  
  471. ; ---------------------------------------------------------------------------
  472. ; Purpose: display a string of characters on the LCD
  473. lcd_write_string_4d:
  474. ; preserve registers
  475. push ZH ; preserve pointer registers
  476. push ZL
  477.  
  478. ; fix up the pointers for use with the 'lpm' instruction
  479. lsl ZL ; shift the pointer one bit left for the lpm instruction
  480. rol ZH
  481.  
  482. ; set up the initial DDRAM address
  483. ori temp, lcd_SetCursor ; convert the plain address to a set cursor instruction
  484. call lcd_write_instruction_4d ; set up the first DDRAM address
  485. ldi temp, 80 ; 40 uS delay (min)
  486. call delayTx1uS
  487.  
  488. ; write the string of characters
  489. lcd_write_string_4d_01:
  490. ld temp, X+
  491. cpi temp, 0 ; check for end of string
  492. breq lcd_write_string_4d_02 ; done
  493.  
  494. ; arrive here if this is a valid character
  495. call lcd_write_character_4d ; display the character
  496. ldi temp, 80 ; 40 uS delay (min)
  497. call delayTx1uS
  498. rjmp lcd_write_string_4d_01 ; not done, send another character
  499.  
  500. ; arrive here when all characters in the message have been sent to the LCD module
  501. lcd_write_string_4d_02:
  502. pop ZL ; restore pointer registers
  503. pop ZH
  504. ret
  505.  
  506. ; ---------------------------------------------------------------------------
  507. ; Purpose: send a byte of information to the LCD data register
  508. lcd_write_character_4d:
  509. sbi lcd_RS_port, lcd_RS_bit ; select the Data Register (RS high)
  510. cbi lcd_E_port, lcd_E_bit ; make sure E is initially low
  511. call lcd_write_4 ; write the upper 4-bits of the data
  512. swap temp ; swap high and low nibbles
  513. call lcd_write_4 ; write the lower 4-bits of the data
  514. ret
  515.  
  516. ; ---------------------------------------------------------------------------
  517. ; Purpose: send a byte of information to the LCD instruction register
  518. lcd_write_instruction_4d:
  519. cbi lcd_RS_port, lcd_RS_bit ; select the Instruction Register (RS low)
  520. cbi lcd_E_port, lcd_E_bit ; make sure E is initially low
  521. call lcd_write_4 ; write the upper 4-bits of the instruction
  522. swap temp ; swap high and low nibbles
  523. call lcd_write_4 ; write the lower 4-bits of the instruction
  524. ret
  525.  
  526. ; ---------------------------------------------------------------------------
  527. ; Purpose: send a nibble (4-bits) of information to the LCD module
  528. lcd_write_4:
  529. ; set up D7
  530. sbi lcd_D7_port, lcd_D7_bit ; assume that the D7 data is '1'
  531. sbrs temp, 7 ; check the actual data value
  532. cbi lcd_D7_port, lcd_D7_bit ; arrive here only if the data was actually '0'
  533.  
  534. ; set up D6
  535. sbi lcd_D6_port, lcd_D6_bit ; repeat for each data bit
  536. sbrs temp, 6
  537. cbi lcd_D6_port, lcd_D6_bit
  538.  
  539. ; set up D5
  540. sbi lcd_D5_port, lcd_D5_bit
  541. sbrs temp, 5
  542. cbi lcd_D5_port, lcd_D5_bit
  543.  
  544. ; set up D4
  545. sbi lcd_D4_port, lcd_D4_bit
  546. sbrs temp, 4
  547. cbi lcd_D4_port, lcd_D4_bit
  548.  
  549. ; write the data
  550. ; 'Address set-up time' (40 nS)
  551. sbi lcd_E_port, lcd_E_bit ; Enable pin high
  552. call delay1uS ; implement 'Data set-up time' (80 nS) and 'Enable pulse width' (230 nS)
  553. cbi lcd_E_port, lcd_E_bit ; Enable pin low
  554. call delay1uS ; implement 'Data hold time' (10 nS) and 'Enable cycle time' (500 nS)
  555. ret
  556.  
  557. ; ============================== End of 4-bit LCD Subroutines ===============
  558.  
  559. ; ============================== Time Delay Subroutines =====================
  560. ; Purpose: provide a delay of (YH:YL) x 1 mS
  561. delayYx1mS:
  562. call delay1mS ; delay for 1 mS
  563. sbiw YH:YL, 1 ; update the the delay counter
  564. brne delayYx1mS ; counter is not zero
  565.  
  566. ; arrive here when delay counter is zero (total delay period is finished)
  567. ret
  568.  
  569. ; ---------------------------------------------------------------------------
  570. ; Purpose: provide a delay of (temp) x 1 mS
  571. delayTx1mS:
  572. call delay1mS ; delay for 1 mS
  573. dec temp ; update the delay counter
  574. brne delayTx1mS ; counter is not zero
  575.  
  576. ; arrive here when delay counter is zero (total delay period is finished)
  577. ret
  578.  
  579. ; ---------------------------------------------------------------------------
  580. ; Purpose: provide a delay of 1 mS
  581. delay1mS:
  582. push YL ; [2] preserve registers
  583. push YH ; [2]
  584. ldi YL, low (((fclk/1000)-18)/4) ; [1] delay counter
  585. ldi YH, high(((fclk/1000)-18)/4) ; [1]
  586.  
  587. delay1mS_01:
  588. sbiw YH:YL, 1 ; [2] update the the delay counter
  589. brne delay1mS_01 ; [2] delay counter is not zero
  590.  
  591. ; arrive here when delay counter is zero
  592. pop YH ; [2] restore registers
  593. pop YL ; [2]
  594. ret ; [4]
  595.  
  596. ; ---------------------------------------------------------------------------
  597. ; Purpose: provide a delay of (temp) x 1 uS with a 16 MHz clock frequency
  598. delayTx1uS:
  599. call delay1uS ; delay for 1 uS
  600. dec temp ; decrement the delay counter
  601. brne delayTx1uS ; counter is not zero
  602.  
  603. ; arrive here when delay counter is zero (total delay period is finished)
  604. ret
  605.  
  606. ; ---------------------------------------------------------------------------
  607. ; Purpose: provide a delay of 1 uS with a 16 MHz clock frequency
  608. delay1uS:
  609. push temp ; [2] these instructions do nothing except consume clock cycles
  610. pop temp ; [2]
  611. push temp ; [2]
  612. pop temp ; [2]
  613. ret ; [4]
  614.  
  615. ; ============================== End of Time Delay Subroutines ==============
  616.  
  617.  
  618. ;
  619. ; projeto area circulo final.asm
  620. ;
  621. ;
Advertisement
Add Comment
Please, Sign In to add comment