Jump to content

SUBIECTE NOI
« 1 / 5 »
RSS
Presbiopia - la 43 ani ?

Termen transcriere autovehicul

Cazare Timisoara pe 4-5 zile

Primele zile ale internetului per...
 Ditra 25

Casti USB-C ptr A-54

Aplicatie medicala / asistent med...

De ce vor atația politicieni...
 ERR_ADDRESS_UNREACHABLE

Legea 18/1968 Se mai aplica?

Digi conectare 2 routere prin fir

Succesiune notar versus instanta ...
 Montaj aer conditionat in balcon ...

Cont curent mulți valuta far...

Sugestii plan casa

Experiente cu firme care cumpara ...
 

Folosirea comunicatiei seriale RS232

- - - - -
  • Please log in to reply
10 replies to this topic

#1
carst_razvan

carst_razvan

    Junior Member

  • Grup: Members
  • Posts: 59
  • Înscris: 16.07.2004
Vreau sa trimit litera "A" folosind RS232 la un calculator. Cum s-ar putea face? (Am incarcat valoarea 0x41 intr-un registru, apoi am folosit un exemplu de program de pe internet care nu prea merge. Cred ca pt. a face transmisia seriala tre' sa folosesc un protocol de comunicatie. Banuiesc ca este Non Return to Zero. Programul folosit este:
"     LIST P=16F84a           ;  tells which processor is used
        #INCLUDE "p16f84a.inc"   ;  defines various registers etc. Look it over.
#include "bank.inc"

        ERRORLEVEL -224        ;  supress annoying message because of tris
        __CONFIG _PWRTE_ON &_LP_OSC &_WDT_OFF   ;  configuration switches

         CBLOCK H'0C'
           txreg              ; holds byte to be transmitted
           rxreg              ; holds byte received
           char               ; holds character to be transmitted
           bitcount           ; holds count of bits when transmitting
           timecnt            ; holds counter for timer
   cont
         ENDC

           ORG 0              ; start a program memory location zero
           goto main          ; skip over subroutines

;-----------------------------------------------------------------------;
;          initialization - set up ports and timer options              ;
;-----------------------------------------------------------------------;
init:
BANK1
movlw 0x1F
movwf TRISA

BANK0
         movlw 0x01    ; RA0 to input
         movwf PORTA           ; contents of W copied to PORT A ...

BANK1
movlw 0x00
movwf TRISB

BANK0
         movlw 0xFF
         movwf PORTB           ; and PORT B

BANK1
         movlw 0x01     ; pull-ups active
movwf OPTION_REG
                              ; prescalar assigned to TMR0 and set 1:4 rolls over each second
         return

;-----------------------------------------------------------------------;
;                        time delay routines                            ;
;-----------------------------------------------------------------------;
onesecond:
  BANK0
          movlw 0x6F           ; wait one second
          movwf timecnt
          clrf TMR0
          bcf INTCON, T0IF     ; clear the interrupt flag

time:
          btfss INTCON, T0IF   ; wait on T0IF to be set
          goto time       ; loop till it is
          decfsz timecnt, 1     ; finished timing?
          goto time             ; not yet
          return                ; yes


;-----------------------------------------------------------------------;
;                     the main program                                  ;
;-----------------------------------------------------------------------;
main:                         ; this is the main program
         call init            ; set up ports
         call onesecond       ; let things settle for 1 second
loop:
         ;call rx               get a character from keyboard
BANK0          ;movwf char            save so we can increment it
movlw 0x41
movwf char
         incf char, f         ; send back the next 3 characters
         movf char, W
         call tx
         incf char, f
         movf char, W
         call tx
         incf char, f
         movf char, W
         call tx
incf char, f
         movf char, W
         call tx
incf char, f
         movf char, W
         call tx
incf char, f
         movf char, W
         call tx
incf char, f
         movf char, W
         call tx
incf char, f
         movf char, W
         call tx
         ;goto loop             do it forever

;-----------------------------------------------------------------------;
;                 transmit byte in W at 1200 baud out RB7               ;
;-----------------------------------------------------------------------;
; normal rs232 is -V for a high, +V for a low
; this would translate to 0V for high +5 for low
tx:
         movwf txreg          ; set up transmit register
         comf txreg, f        ; flip all bits
         movlw D'8'           ; eight bits to transmit
         movwf bitcount
         bsf PORTB, 7         ; start bit (+5V is 'low')
         nop                  ; a total of 7 instruction cycles
         nop                  ; (one is the rrf at txloop)
         nop
         nop
         nop
txloop:
         rrf txreg, f         ; lsb out of txreg into carry
         rrf PORTB, f         ; bit 7 of port B high or low with carry

movlw 0x57
movwf  cont
test1:
decfsz cont,1
goto test1
                            ; make total loop delay 7 instruction counts
                          ; 7 * 122 usec = 854, (should be 833)
         decfsz bitcount, f   ; 4 instruction cycles to here
         goto txloop          ; total 4 + 3 = 7 instructions cycles in loop
         bcf PORTB, 7         ; 0 Volts is the 'high' state this is
         nop                  ; stop bit
         nop                  ; delay 7 instruction cycles
         nop
         nop
         return

;-----------------------------------------------------------------------;
;             receive byte  at 1200 baud in RA0, put in W               ;
;-----------------------------------------------------------------------;
rx:      movlw 0xFF              ; eight bits to input
         movwf bitcount
waspam.spam:
         btfss PORTA, 0       ; wait for input to go high, (start bit)
         goto waspam.spam
         nop                  ; wait 1/2 start bit time 3 including branch
         nop                  ; next four instruction are to make
         nop                  ; 1 bit time delay before first reading of
         nop                  ; input port
         nop
receive:
                        ; make total loop delay 7 instruction counts
                         ; 7 * 122 usec = 854, (should be 833)
movlw 0x57
movwf  cont
test:
decfsz cont,1
goto test

         rrf PORTA, f         ; PORT A bit 0 into carry
         rrf rxreg, f         ; rotate carry into receive register
         decfsz bitcount, f   ;
         goto receive         ; total 4 + 3 = 7 instructions cycles in loop
         comf rxreg, W        ; return compliment of value collected
         nop                  ; wait at least one stop bit
         nop
         nop
         nop
         return

         end
" Am adaptat putin programul pt. rezonatorul meu de 455 KHz)

#2
ThePuiu

ThePuiu

    Active Member

  • Grup: Members
  • Posts: 1,742
  • Înscris: 11.11.2003
Poate ca o sa zica lumea ca sunt nebun (!), dar de ce nu folositi limbajul JAL, oameni buni?!?

Pt transmisii sincrone sau asincrone de date pe seriala nu trebuie scrisa decat o linie de cod !!!

Eu am programat PIC-uri si in asamblare o vreme, dar nu o sa mai pun mana pe el decat daca trebuie facut ceva ce nu se poate face in JAL!
Uite un exemplu:

include 16f84_4
include jlib
include serial

asynch_send ("A")
asynch_send (ASCII_CR)
asynch_send (ASCII_LF)

Nu e mai simplu asa?!?
Bafta!

#3
carst_razvan

carst_razvan

    Junior Member

  • Grup: Members
  • Posts: 59
  • Înscris: 16.07.2004
JAL trebuie apelat din Command Prompt? Exista vreo versiune pentru Windows?

#4
370677271050152

370677271050152

    Member

  • Grup: Members
  • Posts: 554
  • Înscris: 19.05.2002
Eu am cautat o versiune pentru Windows si nu am gasit nicaieri, in linie de comanda habar nu am ca trebuie sa fac

#5
ThePuiu

ThePuiu

    Active Member

  • Grup: Members
  • Posts: 1,742
  • Înscris: 11.11.2003
din pacate, ruleaza din linie de comanda, dar odata facut un fisier *.bat, treaba se rezolva prin simpla apelare a acestuia...
Am vazut zilele trecute pe net un program in windows care apela JAL-ul si permitea editarea sursei in editorul propriu...nu stiu daca se justifica atata timp cat un editor bun este si notepad-ul...
in cazul meu, fisierul bat are continutul:

c:picjalbinjal.exe -sc:picjallib c:picjalworktest.jal

unde test.jal este sursa la care lucrez...

Bafta!

#6
carst_razvan

carst_razvan

    Junior Member

  • Grup: Members
  • Posts: 59
  • Înscris: 16.07.2004
Am facut un fisier test.jal scris in Notepad. In momentul in care am dat sa generez bin-ul a spus ca nu poate deschide fisierul test.jal

#7
DeeJay

DeeJay

    Senior Member

  • Grup: Senior Members
  • Posts: 2,086
  • Înscris: 07.05.2004
JalEdit

Attached Files



#8
ThePuiu

ThePuiu

    Active Member

  • Grup: Members
  • Posts: 1,742
  • Înscris: 11.11.2003
ai grija la numele directoarelor unde este pus JAL-ul si fisierul in care lucrezi...sau foloseste editorul de la deejay2k1

Bafta!

#9
carst_razvan

carst_razvan

    Junior Member

  • Grup: Members
  • Posts: 59
  • Înscris: 16.07.2004
Editorul deejay2k1 unde il pot gasi?

Daca tot pot folosi jal-ul, ajutati-ma cu ceva documentatie
Multumesc

#10
ThePuiu

ThePuiu

    Active Member

  • Grup: Members
  • Posts: 1,742
  • Înscris: 11.11.2003
Editorul il poti gasi cu 2 posturi mai sus... :ciocan:
Documentatie.....cauta pe net...
:cya:

#11
carst_razvan

carst_razvan

    Junior Member

  • Grup: Members
  • Posts: 59
  • Înscris: 16.07.2004
Multani fain, nu prea sunt atent nea Puiu

Anunturi

Bun venit pe Forumul Softpedia!

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Forumul Softpedia foloseste "cookies" pentru a imbunatati experienta utilizatorilor Accept
Pentru detalii si optiuni legate de cookies si datele personale, consultati Politica de utilizare cookies si Politica de confidentialitate