
Interface Example PIC16F628 Reading TLC548 Serial ADC
by Lewis Loflin
The following program will read the 8-bit value from a TLC548 ADC and display the binary values on eight LEDs connected to PORTB. This page discusses parts of the programming. Note that many of these programs work on a PIC16F84A unless one needs comparators or pulse-width-modulation.
See the complete program: TLC548_binary.asm
;-------------------------------------- DATABIT equ 0 ; DATA bit TLC548 pin 6 to RA0 CLK equ 1 ; CLK TLC548 pin 7 to RA1 CS equ 2 ; select TLC548 pin 5 to RA2 ;---------------------------------------
Above is the pin connections to the TLC548 serial analog-to-digital converter. This has three control pins labeled CS, Data Out, IO clock. They are connected RA0, RA1, and RA2 as shown above.
read_adc ; value returned in val clrf val bcf PORTA, CS ; LOW CS movlw 0x08 movwf i zz bsf PORTA, CLK ; HIGH CLK call delay_1ms btfss PORTA, DATABIT goto $+3 movlw 0x01 addwf val, F bcf PORTA, CLK ; LOW CLK decfsz i, F goto $+3 goto $+4 nop rlf val goto zz bsf PORTA, CS ; HIGH CS return
Above is the assembly language ADC subroutine. It uses a temp variable i is a counter index and returns the 8-bit value in val. It works as follows:
i = 8;
CS is taken LOW to select device;
CLK is taken HIGH - a LOW to HIGH transition shift out 1st MSB;
delay 1mSec ;
DATABIT either a HIGH or LOW is added to val
CLK goes LOW;
val is shifted left one position;
i is decremented by 1;
process repeats 8 times and exits when i = 0;
CS is set HIGH.
main call read_adc ; value returned in val movf val, w movwf PORTB ; display val at PORTB LEDs call delay_100ms goto main
Main program loop.
See tlc548.pdf
See How I got into Electronics
- You Tube Videos for this Series
- Home Built PIC Development Board
- PIC16F628 PIC Using Rotary Encoder to Operate Stepper Motor
- Using a Serial ADC with PIC16F628
- Calculating Pulse-Width Modulation with a PIC
- PIC16F84A-628A Hardware Time Delays
- PIC16F84A-628A Timer Interrupt Delays
- PIC16F84A-628A Pullups and Interrupts
- PIC16F84A-628A Hardware Interrupts Tutorial
- Projects using PIC16F628:
- Home Built PIC16F628 Prototyping Board
- Exploring the Microchip PIC in Assembly
- Using a Microchip PIC with TLC548 Serial ADC
- Controlling PIC Pulse Width Modulation with a Serial ADC
- Using TMR0 on a PIC with Interrupts
- External Clock Crystal with PIC16F628 TMR1 Generates Interrupt
- PIC Using Rotary Encoder to Operate Stepper Motor
- PIC16F628 Pulse Width Modulation Controls Brightness of LED
- Another way to Turn On-Off PWM in a PIC
- TLC548 Serial ADC Spec. Sheet
- Programming PIC16F84A-PIC16F628A Interrupts by Example
- PIC16F84A-PIC16F628A Pull Up Resistors with Interrupts
- Programming PIC16F84A-PIC16f628a Timers by Example
- Programming PIC16F84A-PIC16F628A TMR0 Interrupts
- Programming PIC16F84A Software Delay Routines by Example
Web site Copyright Lewis Loflin, All rights reserved.
If using this material on another site, please provide a link back to my site.