USB Handler

takao21203

Joined Apr 28, 2012
3,702
Ah yes I see a bit.

I2C is nothing new, has been around for a long while and is pretty much a standard.

Most serial chips either use synchronous serial (SPI) or I2C.

When you program serial I/O in most cases you deal with TFTs or serial memory and sensors.

Better learn I2C, serial memory and graphics TFT.

You can use the GAL programmer to write serial FLASH if it is not too dated.

I am not talking about the latest technology that would be leadless ICs, flex PCBs, software CPU cores on a FPGA and things like that.

But about to mothball linear regulators, 9V batteries, large LED display boards, and assembler. This stuff belongs to the early 1970s.

Innovation can be made by using older technology in a new way, but especially assembler is more a blocking to that than anything else.

Hordes of young people used assembler in the late 1980s and early 1990s. It all ended at some point of time and led to nowhere.

But logically, you should be able to use a serial EEPROM at first, before you try to program a software USART.

A software USART with no defined purpose has no right for existance.

My opinion is create solutions, don't deal with absurd toy problems. Learn to create a solution, then maybe do some toy problem circuits.

Nothing stopping you from:

-Learn I2C
-And do a software synchronous USART
-And do a software asynchronous USART as well if you feel need be and haveing fun with it.

But in that order as above.

Because I2C is a defined standard, and synchronous USART is easier.
 

Thread Starter

David_Baratheon

Joined Feb 10, 2012
285
Ok sure Im happy to look at it in my own time but I do still need to produce the work for Uni aswell

I agree that its old technology but I really can't help it as that is the choice of the Uni
 

takao21203

Joined Apr 28, 2012
3,702
I have not yet understood if it has to be asynchronous.

You also need a crystal for that or you get additional deviation from a resonator. The allowed deviation is some 3% (for the timing), but this should not be maxed out.
 

Markd77

Joined Sep 7, 2009
2,806
You should have enough information to make a start now. The simulator in MPLAB will be useful for initial testing, then hook it up to the PC using a MAX232 chip or similar. Hterm is a pretty decent free serial terminal program. It allows you to easily send and receive bytes and unlike a text only serial terminal, you can easily send and receive all possible hex values.
http://www.der-hammer.info/terminal/
The program is English language although the website isn't.
 
Last edited:

ErnieM

Joined Apr 24, 2011
8,377
David , you will get lots of silly misinformation here. Keeping at your studies is the proper move for you, and other things when and if time allows. Perhaps the professor's intent here is to have you do a task first in assembler, then in C to let you see for yourself the productivity increase. Besides, it's his course and his rules.

RS232 is not dead yet.
 
Last edited:

takao21203

Joined Apr 28, 2012
3,702
Two questionable skills:

A) putting words into someone's mouths. Even on MSDN someone broke the firewall of etiquette and directly asked me not to do it.

B) making a judgement on the behalf of someone else. It lets this person stand in a poor light unable to decide upon oneself.

RS232 is pointless from the view of the costs.

Make the calculation yourself, as for USB, cost is $3 for a prototype, including cable, socket, and USB PIC.

RS232 cables aren't cheap and are not good for nothing else.

Of course it is not yet dead but there is no need to pay much attention to it. Unless you already deal with it for a long while.

On a sidetrack, I like the Microchip technology, because it is useful. Never requesting free samples.

For A), I'd have to wait a long time, and B), I could not really do with them what I want. If I buy them, they are my property. If I claim a freebie, I must feel thankful or something or I must tell weird stories of how about I eventually lied to people (which I did not do).

Abusing a TQFP adapter is eventually an unique method it is pratically however. You need to have the cheapest one made from thin brittle PCB, or it is quite a hassle to remove the other half you don't need or don't want.

The soldering is not difficult with 1mm solder wire and a broad tip.

The larger rectangular sockets actually have small and brittle pins you'd see yourself how it is to deal with these.

USB is an actual replacement for RS232, not only for PC. It is also used via USB hosting controllers.

Compare the teaching method at this university:

-Implement a software USART eventually use assembler even, and count clock cycles, as well think about a complicate scheme.

to using the USB stack:

-Download the already working C source, compile it, solder a chip to a board, and actually use it for some purpose.

Why actually understand all details about USB and the hardware registers? It is not dealt with as a prerequisite to use it.

Of course you'd be able to write RS232 software USART and stuff if you wanted to. Otherwise you'd choose another profession or not to deal with technology.

In my opinion, the approach in the industry has changed.

In the 1950s servicemen took your TV, and measured the board and replaced valves or you even were able to do it yourself.

In the 1970s it changed, only a complete PCB was exchanged.

It changed again, now the complete unit is discarded. It is cheaper in the end in many cases.

One of the most weird phenomena is this TB303 drum computer. The street price is now heading 1000 to 2000 dollars depending on condition.

It is possible to construct the circuit for about 50 dollar.

It is really only built from ordinary small signal transistors, and a small cheap microcontroller.

Now what are these scene wizards doing? Hoarding lists with the ordering number for original replacement parts which contain the part number and which of course are no longer available and get excited about that. Buying up even several broken one's and extracting these parts and resell for high prices.

Silly is not even remotely describing this.

Really producing it that way only 20000 units then halting production early was a masterpiece of marketing. Slowly it trickled into secondary markets and eventually is still around.

On Youtube: https://www.youtube.com/watch?v=omHUR3R0Qqw

You should listen carefully as it is highly educational and is not shy to put a light on a scene of people.
 

Attachments

MMcLaren

Joined Feb 14, 2010
861
Hi David,

If you're still looking for a bit-banged serial code example, here's an example program for 12F1822 for 9600 baud using TX on RA0 and RX on RA1. I tested the program by connecting it to my PC using a usb-to-serial adapter and running Hyperterminal software on the PC.

Good luck in your studies.

Cheerful regards, Mike

Rich (BB code):
;******************************************************************
;                                                                 *
;   Filename: 12F1822 Soft Serial Demo                            *
;     Author: Mike McLaren, K8LH                                  *
;       Date: 27-Feb-2013                                         *
;                                                                 *
;   12F1822 Bit-Banged Serial Demo                                *
;                                                                 *
;                                                                 *
;      MPLab: 8.50    (tabs=8)                                    *
;      MPAsm: 5.35                                                *
;                                                                 *
;******************************************************************

    #include <P12F1822.INC>
    radix dec
    errorlevel -302
    list st=off

  __CONFIG _CONFIG1, _FOSC_INTOSC & _WDTE_OFF & _MCLRE_ON & _IESO_OFF & _FCMEN_OFF
  __CONFIG _CONFIG2, _BORV_19 & _LVP_OFF & _PLLEN_OFF
;
; _MCLRE_ON     default
; _PWRTE_OFF    default
; _CP_OFF       default
; _CPD_OFF      default
; _BOREN_ON     default
; _CLKOUTEN_OFF default
;
; _WRT_OFF      default
; _STVREN_ON    default
;

;--< variables >---------------------------------------------------
        cblock  0x20
rxbyte                          ; Get232 variable
txbyte                          ; Put232 variable
bitctr                          ; Get232/Put232 work variable
delayhi                         ; DelayCy() subsystem variable
        endc

;--< constants >---------------------------------------------------

TxPin   equ     0               ; Tx pin on RA0
RxPin   equ     1               ; Rx pin on RA1


;******************************************************************
;  K8LH DelayCy() subsystem macro generates four instructions      *
;******************************************************************
        radix   dec
clock   equ     4               ; 4, 8, 12, 16, 20 (MHz), etc.
usecs   equ     clock/4         ; cycles/microsecond multiplier
msecs   equ     clock/4*1000    ; cycles/millisecond multiplier

DelayCy macro   delay           ; 11..327690 cycle range
        movlw   high((delay-11)/5)+1
        movwf   delayhi
        movlw   low ((delay-11)/5)
        call    uDelay-((delay-11)%5)
        endm

;******************************************************************
;  reset vector                                                   *
;******************************************************************
    org    0x0000
v_reset
        banksel OSCCON          ; bank 1                          |B1
        movlw   b'01101010'     ;                                 |B1
        movwf   OSCCON          ; setup 4-MHz INTOSC              |B1
waitfs  btfss   OSCSTAT,HFIOFS  ; stable? yes, skip, else         |B1
        bra     waitfs          ; branch and wait                 |B1
;
;  configure ports
;
        banksel ANSELA          ; bank 3                          |B3
        clrf    ANSELA          ; set digital I/O                 |B3
        banksel TRISA           ; bank 1                          |B1
        movlw   1<<RxPin        ;                                 |B1
        movwf   TRISA           ; RxPin input, others output      |B1
        banksel LATA            ; bank 2                          |B2
        movlw   1<<TxPin        ;                                 |B2
        movwf   LATA            ; set TxPin to 'stop' state       |B2
        movlb   0               ; bank 0                          |B0

;******************************************************************
;  main loop                                                      *
;******************************************************************

loop
    call    Get232          ; get a char from terminal        |B0
    call    Put232          ; echo it back to terminal        |B0
    bra     loop            ;                                 |B0

;******************************************************************
;  Get232 bit-banged serial RX subroutine                         *
;******************************************************************

Get232
        btfsc   PORTA,RxPin     ; start bit (0)? yes, skip, else  |B0
        bra     Get232          ; loop (wait for start bit)       |B0
        DelayCy(104*usecs/2)    ; delay 1/2 bit time              |B0
        movlw   8               ;                                 |B0
        movwf   bitctr          ; BitCtr = 8                      |B0
RxBit
        DelayCy(104*usecs-7)    ; precise 52-usec bit timing      |B0
        clrc                    ; assume '0'                      |B0
        btfsc   PORTA,RxPin     ; a '0' bit? yes, skip, else      |B0
        setc                    ; set to '1'                      |B0
        rrf     rxbyte,F        ; capture bit from Carry          |B0
        decfsz  bitctr,F        ; done? yes, skip, else           |B0
        goto    RxBit           ; get another bit                 |B0
        movf    rxbyte,W        ; return "rxbyte" in WREG         |B0
        return                  ;                                 |B0

;******************************************************************
;  Put232 bit-banged serial TX subroutine                         *
;******************************************************************

Put232
        banksel txbyte          ; bank 0                          |B0
        movwf   txbyte          ; save Tx data byte               |B0
        movlw   10              ; 1 start + 8 data + 1 stop bit   |B0
        movwf   bitctr          ; setup bit counter               |B0
        clrc                    ; C = 0 (start bit)               |B0
        goto    SendBit         ; send start bit                  |B0
TxBit
        DelayCy(104*usecs-10)   ; 104 usecs -10 cycle loop time   |B0
        setc                    ; always shift in a 'stop' bit    |B0
        rrf     txbyte,F        ; put data bit in Carry           |B0
SendBit
        movf    PORTA,W         ; read port                       |B0
        iorlw   1<<TxPin        ; set TxPin bit to 1              |B0
        skpc                    ; if data bit = 1 skip, else      |B0
        xorlw   1<<TxPin        ; set TxPin bit to 0              |B0
        movwf   PORTA           ; precise "bit Time" intervals    |B0
        decfsz  bitctr,F        ; done? yes, skip, else           |B0
        goto    TxBit           ; send next bit                   |B0
        return                  ;                                 |B0
   
;******************************************************************
;  K8LH DelayCy() sub-system 16-bit udelay subroutine             *
;******************************************************************

        nop                     ; entry for (delay-11)%5 == 4     |B0
        nop                     ; entry for (delay-11)%5 == 3     |B0
        nop                     ; entry for (delay-11)%5 == 2     |B0
        nop                     ; entry for (delay-11)%5 == 1     |B0
uDelay  addlw   -1              ; subtract 5 cycle loop time      |B0
        skpc                    ; borrow? no, skip, else          |B0
        decfsz  delayhi,F       ; done?  yes, skip, else          |B0
        goto    uDelay          ; do another loop                 |B0
        return                  ;                                 |B0

;******************************************************************
    end
 
Last edited:
Top