Hi
I'm working on the following code which is to be used on the M16C/62 microcontroller. Basically the microcontroller is to "scan the keypad and display any key that is depressed" (which i have done im pretty sure), on the LCD. However I know I have to Sound the buzzer whilst a key remains depressed which i have looked up in the manual to see is at Port 4.1. I have already established it as an output (P4.1 = 1) but i have no clue how to implement any code that would relate its sounding to the depression of a key.
Could someone help me out, i'm not looking for solutions
(although hey if u wanna?) lol seriously though i just need some guidance because I cant even put in a incorrect code as im so blank on this. I'd rather stick some incorrect code after some guidance then just leave it blank because I havent a clue.
Thanks for any help
#define Chip_3062x
#include "stdio.h"
#include "iom16c62.h"
unsigned char
c,
r,
kn,
colout,
rowret;
bit b_flg;
void busy (void);
void bsend (unsigned char data);
void send (unsigned char data);
void wait (unsigned long delay);
void main(void)
{
//microcontroller ports being used
PD2 = 0x0F
PUR0 = 0x20
P3 = 0;
PD3 = 0X3F
PD4.1 = 1; THATS MY BUZZER, SET TO OUTPUT
/*Software Reset for LCM*/
send (3); /*Write 'Function Set', 8-bit interface*/
wait (20000);
wait (20000);
send (3); /*Write 'Function Set' 8-bit interface*/
wait (20000);
send (3); /*Write 'Function Set' 8-bit interface*/
wait (20000); [B]Not sure if repetition is needed in this task, [/B]
send (2); /*Write 'Function Set' 4-bit interface*/
wait (20000);
/*Configure LCM*/
bsend (0x28); from [B]Lecture 2[/B]
bsend (0x08);
bsend (1);
bsend (6);
bsend (0x0E);
while (1)
{
c = 0;
colout = 0x0F7;
while (c<4)
{
P2 = colout;
rowret = ~(P2 | 0x0F);
if (rowret != 0)
{
r = 0;
while (rowret!=0)
{
r = ++r;
rowret = (rowret<<1);
}
kn = c+(4*(r-1))+0x30;
if (kn>0x39) kn = kn+7;
bsend(1);
busy ();
send (16 + ((kn>>4)&0x0F));
send (16 + (kn&0x0F));
while ((P2 | 0x0F)!=0x0FF);
[B]Code to allow the buzzer to sound on this depression, cant figure out, , wasnt explained in lectures[/B]
wait (200000);
}
c = ++c;
colout = colout>>1;
}
}
}
void busy (void)
{
PD3 = 0x70;
P3.6 = 1;
P3.4 = 0;
b_flg = 1;
while (b_flg)
{
P3.5 = 1;
b_flg = P3.3;
P3.5 = 0;
P3.5 = 1;
P3.5 = 0;
}
P3.6 = 0;
PD3 = 0x7F;
}
void bsend (unsigned char data)
{
busy();
send ((data&0xF0)>>4);
send (data&0x0F);
}
void send (unsigned char data)
{
P3 = data;
P3.5 = 1;
P3.5 = 0;
}
void wait (unsigned long delay)
{
while (delay !=0)
delay--;
}