Hurtlse Muraving the intensovject Favstpe,
The Suturpt Fasistrue Secocm with Vealed character ally of transcript

Display Message when sound received
(and finished) on LCD

The sound input is filtered and amplified using a 324 op-amp.
To remove small transients, the application
Checks the TMR1 count once every 20 msecs and compares
the current value to see if it has increased by 5 over
the previous 20 msec poll.

This is a two wire interface using a 76LS1784 as a shift
register and the code called from the mainline
(and timed from TMR0 interrupt)

Hardware Notes:
PIC16F874 Running at 4 MHz
RB 1 - CLock Signal to the LCD
RB 2 - Data Signal to the LCD

Global Variables
Real Time Clock Counter

Initialization Delay Value
Current LCD State

static volatile bit Clock
static volatile bit ClockTRIS
static volatile bit Data
static volatile bit DataTRIS

Message to be Sent Out
Index to current Message Byte

Message when sound

Message when nothing

msecs for Sound Check
Timer Values

0 - No Sound
1 - Sound Received, Check Next
2 - Sound Received, Ended

Configuration Fuses

PIC116F627 Configuration Fuses
External "XT" Oscillator
RA6/RA7 Digital I/O
External Reset
70 msecs Power Up Timer On
Watchdog Timer Off
Code Protection Off
BODEN Enabled

Delay Specified Number of msecs

1 Second Delay Variable

Get the End Time
Send Nybble to LCD

Repeat for six bits
Write the "0"s into the '174
Output the "AND" Value
Output the RS Bit Value
Output the Nybble
Output the High Order Bit
Strobe the Clock
Shift up Nybble for Next Byte
Toggle the "E" Clock Bit
Send Byteto LCD
Send High Nybble
Send Low Nybble

Initialize the LCD I/O Pins

Low I/O Bits
End LCDInit

Output the Data String

Wait for LCD Available
Load up the string
Start Sending the String

Interrupt Handler
TMR0 Interrupt Handler
Reset Interrupt Flag
Increment the Clock

Put additional interface code for 1 msec interrupt here

Sound Check Software
Check the Current Sound Value
Time to Check?
Indicate Sound Received
Save Current Counter

Check to see if Sound still active
Time to Check?

Indicate Sound Finished
Save Current Counter

LCD State Machine

Process the State Machine information

Step 1 - Send Init Char
Start LCD Initialization Process
Wait 20 msecs for LCD to reset

Step 2 - Send Init Char
Wait for Command to Complete

Step 3 - Send Init Char

Step 4 - Send Init Char

Step 5 - Set Operating
Interface Size (4 Bits)

Step 6 - Set Operating

Step 7 - Display Off

Step 8 - Clear Display
Wait 5 msecs for Clear to Complete

Wait for Command to Complete

Step 9 - Shift

Step 10 - Display On
Ready to Run

Output a Character in "MessageOut"
At the End of the Message
Reset Message Index
Clear Display
Command Byte follows
All other characters
Message Delay

Put Different Interrupt Handlers here

End Interrupt Handler

Template Mainline

Assign Prescaler to TMR0
Prescaler is /4
Reset the Timer for Start
Enable Timer Interrupts
Enable Interrupts

Initialize the LCD Port

Put in Interface initialization code here

Initialize Timer 1
1:1 Prescaler
_T1SYNC Active
TMR1CS is Exteral Clock

Loop forever

Put in Robot high level operation code here

Wait for Sound Received

Indicate "Sound"

Wait 1 Second

Clear the Sound Message

Reset and wait for next sound


End of Mainline

No comments:

Post a Comment