Spell Number Program in C

Posted by Luki on Sunday, May 8, 2011


This program will spell our input number with the maximum number is 999.999.999. This spelling method uses bahasa Indonesia but It doesn’t have many differences with English.


#include <stdio.h>
#include <stddef.h>
#include <stdlib.h>

char a[];
char temp[];
int i;

void tulis (char c)
{
  switch (c)
  {
    case '1':
    printf ("satu ");
    break;
    case '2':
    printf ("dua ");
    break;
    case '3':
    printf ("tiga ");
    break;
    case '4':
    printf ("empat ");
    break;
    case '5':
    printf ("lima ");
    break;
    case '6':
    printf ("enam ");
    break;
    case '7':
    printf ("tujuh ");
    break;
    case '8':
    printf ("delapan ");
    break;
    case '9':
    printf ("sembilan ");
    break;
  }
}

void tukar (int d)
{
  for (i=0;i=0;i--)
  {
    if (i==6 || i==3 || i==0)
    {
      if (temp[i]=='0' && b==1)
      {printf ("nol ");}
      else if (temp[i]=='1' && b==4)
      {printf ("se");}
      else
      {
        if (temp[i+1]!='1')
        {tulis(temp[i]);}
      }
    }
    else if (i==7 || i==4 || i==1)
    {
      if (temp[i]=='1' && temp[i-1]=='0')
      {
        printf("sepuluh ");
      }
      else if (temp[i]=='1' && temp[i-1]=='1')
      {
        printf("sebelas ");
      }
      else
      {
        if (temp[i]=='1')
        {tulis(temp[i-1]);
        printf("belas ");}
        else if (temp[i]!='0' && temp[i]!='1')
        {tulis(temp[i]);
        printf("puluh ");}
      }
    }
    else if (i==8 || i==5 || i==2)
    {
      if(temp[i]=='1')
      {printf("seratus ");}
      else if (temp[i]!='0' && temp[i]!='1')
      {tulis(temp[i]);
      printf("ratus ");}
    }

  if (i==6)
  {
    printf("juta ");
  }
  else if (i==3)
  {
    printf("ribu ");
  }

}

return 0;
}

Download Spell Number Program (tes.exe) (run in Command Prompt)


More aboutSpell Number Program in C

Site Contact

Posted by Luki on Monday, December 6, 2010

If you have any question or reques, You can conatct me at : contact@digitalelectrical.info 


You can give donation to help me improve this site for more resources.



More aboutSite Contact

Basic Elements of Digital Signal Processing System

Posted by Luki on Saturday, December 4, 2010

Most of the signals encountered in science and engineering are analog in nature. That is the signals are functions of a continuous variable, such as time or space, and usually take on values in a continuous range. Such signals may be processed directly by appropriate analog systems (such as filters or frequency analyzers) or frequency multipliers for the purpose of changing their characteristics or extracting some desired information. In such a case we say that the signal has been processed directly in its analog form, as illustrated in picture below.
 Both the input signal and the output signal are in analog form.

Digital signal processing provides an alternative method for processing the analog signal, as illustrated in figure below.


To perform the processing digitally, there is a need for an interface between the analog signal and the digital processor. This interface is called an analog-to-digital (A/D) converter. The output of the A?D converter is a digital signal that is appropriate as an input to the digital processor.

The digital signal processor may be a large programmable digital computer or a small microprocessor programmed to perform the desired operations on the input signal. It may also be a hardwired digital processor configured to perform a specified set of operations on the input signal. Programmable machines provide the flexibility to change the signal processing operations through a change in the software, whereas hardwired machines are difficult to reconfigure. Consequently, programmable signal processors are in very common use. On the other hand, when signal processing operations are well defined, a hardwired implementation of the operations can be optimized, resulting in a cheaper signal processor and, usually, one that runs faster than its programmable counterpart. In applications where the digital output from the digital signal processor is to be given to the user in analog form, such as in speech communications, we must provide another interface from the digital domain to analog domain. Such an interface is called a digital-to-analog (D/A) converter. Thus the signal is provided to the user in analog form.

However, there are other practical applications involving signal analysis, where the desired information is conveyed in digital form and no D/A converter is required. For example, in the digital processing of radar signals, the information extracted from the radar signal, such as the position of the aircraft and its speed, may simply be printed on paper. There is no need for a D/A converter in this case.

http://digitalelectrical.info
More aboutBasic Elements of Digital Signal Processing System

Serial Communication of 2 Processors

Posted by Luki on Friday, December 3, 2010


This project uses 2 Atmega16 with 16 MHz external clock. The first microcontroller is used to capture inputs from keypad 4 x 4. The second microcontroller is used to show outputs on LCD HD44780 2 x 16. I use asynchronous mode for this project.

This is the schematic:
But if you want to use synchronous mode, PINB.0 of first AVR should be connected to PINB.0 of second AVR.

This is the sample of this project that I have made.


If you want to know how to connect AVR with LCD HD44780, see my other post here.
If you need source code just email me at contact@digitalelectrical.info



http://digitalelectrical.info
More aboutSerial Communication of 2 Processors

How to Connect LCD HD44780 with AVR

Posted by Luki


LCD HD44780 is one kind of LCD that is commonly used by many students and developers in many countries for learning objectives. If we want to use this LCD, we should connect it with a microcontroller as the control system. The most popular microcontroller for students and developers is AVR, a kind of microcontroller from Atmel.  
There is a simple way to communicate LCD HD44780 with AVR microcontroller. You can use library that have been made by winavr.scienprog.com team so it will be easy to set your AVR microcontroller. These are the steps:
1.       You should have the library in your work directory. You can download lcd_lib.h, lcd_lib.c and datasheet of LCD here.
2.       The default output port for LCD that is defined in the library is port D. You can change the port by making some changes on preprocessor in the header file at this part:
#define LDP PORTD
#define LCP PORTD
#define LDDR DDRD
#define LCDR DDRD
3.       There are some basic functions that you can use. You can learn it from demo program that have been made by winavr.scienprog.com team. At that demo program you can learn some basic function such as sending a char, sending a string, moving the cursor in LCD, etc. You can download demo program and datasheet here.
4.       This library uses 4 bit data to operate the LCD so you use only 4 LCD data pins. You can see the configuration of the LCD pin below.

PIN
Description
If using the library
1
GND
connect it to GND
2
Vcc
connect it to Vcc (put 1k resistor to reduce the current)
3
Vee
connect it to GND (if you don’t want to change contrast)
4
R/S
to PD0
5
R/W
to PD1
6
E
to PD2
7
D0

8
D1

9
D2

10
D3

11
D4
to PD4
12
D5
to PD5
13
D6
to PD6
14
D7
to PD7
15
D8
V+ (only if LCD has backlight)
16
D9
GND (only if LCD has backlight)

5.       Make design of your system and apply it. If you want to be more expert, you can upgrade your system for example by adding a keypad or push button to your system as input device.  This is a basic skill to make more advanced device such as digital clock, digital game, etc.


http://digitalelectrical.info
More aboutHow to Connect LCD HD44780 with AVR

Introducing to USART in AVR

Posted by Luki on Thursday, November 25, 2010


USART in AVR

The Universal Synchronous and Asynchronous serial Receiver and Transmitter (USART) is a highly flexible serial communication device. The main features are:
• Full Duplex Operation (Independent Serial Receive and Transmit Registers)
• Asynchronous or Synchronous Operation
• Master or Slave Clocked Synchronous Operation
• High Resolution Baud Rate Generator
• Supports Serial Frames with 5, 6, 7, 8, or 9 Data Bits and 1 or 2 Stop Bits
• Odd or Even Parity Generation and Parity Check Supported by Hardware
• Data OverRun Detection
• Framing Error Detection
• Noise Filtering Includes False Start Bit Detection and Digital Low Pass Filter
• Three Separate Interrupts on TX Complete, TX Data Register Empty and RX Complete
• Multi-processor Communication Mode
• Double Speed Asynchronous Communication Mode


AVR USART vs. AVR UART – Compatibility

The USART is fully compatible with the AVR UART regarding:
• Bit locations inside all USART Registers
• Baud Rate Generation
• Transmitter Operation
• Transmit Buffer Functionality
• Receiver Operation

However, the receive buffering has two improvements that will affect the compatibility in some special cases:
• A second buffer register has been added. The two buffer registers operate as a circular FIFO buffer. Therefore the UDR must only be read once for each incoming data! More important is the fact that the Error Flags (FE and DOR) and the ninth data bit (RXB8) are buffered with the data in the receive buffer. Therefore the status bits must always be read before the UDR Register is read. Otherwise the error status will be lost since the buffer state is lost.
• The Receiver Shift Register can now act as a third buffer level. This is done by allowing the received data to remain in the serial Shift Register (see Figure 69) if the buffer registers are full, until a new start bit is detected. The USART is therefore more resistant to Data OverRun (DOR) error conditions.

The following control bits have changed name, but have same functionality and register location:
• CHR9 is changed to UCSZ2
• OR is changed to DOR


Clock Generation

The clock generation logic generates the base clock for the Transmitter and Receiver. The USART supports four modes of clock operation: Normal asynchronous, Double Speed asynchronous, Master synchronous and Slave synchronous mode. The UMSEL bit in USART Control and Status Register C (UCSRC) selects between asynchronous and synchronous operation. Double Speed (asynchronous mode only) is controlled by the U2X found in the UCSRA Register. When using Synchronous mode (UMSEL = 1), the Data Direction Register for the XCK pin (DDR_XCK) controls whether the clock source is internal (Master mode) or external (Slave mode). The XCK pin is only active when using synchronous mode.


Internal Clock Generation – The Baud Rate Generator

Internal clock generation is used for the asynchronous and the synchronous master modes of operation. The USART Baud Rate Register (UBRR) and the down-counter connected to it function as a programmable prescaler or baud rate generator. The down-counter, running at system clock (fosc), is loaded with the UBRR value each time the counter has counted down to zero or when the UBRRL Register is written. A clock is generated each time the counter reaches zero. This clock is the baud rate generator clock output (= fosc/(UBRR+1)). The Transmitter divides the baud rate generator clock output by 2, 8, or 16 depending on mode. The baud rate generator output is used directly by the receiver’s clock and data recovery units. However, the recovery units use a state machine that uses 2, 8, or 16 states depending on mode set by the state of the UMSEL, U2X and DDR_XCK bits. Table below contains equations for calculating the baud rate (in bits per second) and for calculating the UBRR value for each mode of operation using an internally generated clock source.


Double Speed Operation (U2X)

The transfer rate can be doubled by setting the U2X bit in UCSRA. Setting this bit only has effect for the asynchronous operation. Set this bit to zero when using synchronous operation. Setting this bit will reduce the divisor of the baud rate divider from 16 to 8, effectively doubling the transfer rate for asynchronous communication. Note however that the Receiver will in this case only use half the number of samples (reduced from 16 to 8) for data sampling and clock recovery, and therefore a more accurate baud rate setting and system clock are required when this mode is used. For the Transmitter, there are no downsides.


External Clock

External clocking is used by the synchronous slave modes of operation. The description in this section refers to Figure 70 for details. External clock input from the XCK pin is sampled by a synchronization register to minimize the chance of meta-stability. The output from the synchronization register must then pass through an edge detector before it can be used by the Transmitter and Receiver. This process introduces a two CPU clock period delay and therefore the maximum external XCK clock frequency is limited by the following equation:
 Note that fosc depends on the stability of the system clock source. It is therefore recommended to add some margin to avoid possible loss of data due to frequency variations.


Synchronous Clock Operation

When Synchronous mode is used (UMSEL = 1), the XCK pin will be used as either clock input (Slave) or  clock output (Master). The dependency between the clock edges and data sampling or data change is the same. The basic principle is that data input (on RxD) is sampled at the opposite XCK clock edge of the edge the data output (TxD) is changed.

The UCPOL bit UCRSC selects which XCK clock edge is used for data sampling and which is used for data change. As Figure 71 shows, when UCPOL is zero the data will be changed at rising XCK edge and sampled at falling XCK edge. If UCPOL is set, the data will be changed at falling XCK edge and sampled at rising XCK edge.

source: datasheetatmega8535
http://digitalelectrical.info
More aboutIntroducing to USART in AVR