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--;
    }

I think that embedded software topics are not relevant for DaniWeb type forums. It's a very interesing but too specialized area. As usually, no common programming language problems there. See your problem, for example: you need help on the particular device programming (ports, time-outs etc).
Better ask the question on the M16C community forum (or download examples, device datasheets, other documentation etc). For example, look at:
http://www.renesasrulz.com/
http://america.renesas.com/fmwk.jsp?cnt=Application_Notes.jsp&fp=/products/mpumcu/m16c_family/&dscl=disclaimer8.html&title=Application%20Notes&lid=49
...
Of course, may be there is M16C profi here but I'm doubt...
Good luck!

Yikes. It's too hard to help you because I am totally unfamiliar with that particular chips op codes. And I'm not familiar with that header file either. Generally these forums are for windows/linux programmers. Does this need to be written in C++? Because if it can be written in assembly, I may be able to help. There is most likely a register or reserved memory address, which needs to be looked up, that contains a boolean bit or some other flag mechanism to trigger the buzzer to be activated. Since there's a header file included for the chip, there is likely definitions specific to activating the buzzer, and if not some in depth reading must be done to determine it's address/register.

This article has been dead for over six months. Start a new discussion instead.