Mar 5, 2010
How to access R0 to R7 registers in Keil C?
{
unsigned char R0Val;
_asm
MOV A, R0
MOV _R0Val, A
_endasm
}
OR
{
unsigned char R0Val;
#pragma ASM
MOV A, R0
MOV _R0Val, A
#pragma ENDASM
}
C variables have to be prefixed by '_' or underscore character, to be accessible in the assembly section of the C code.
Hope this helps.
Feb 25, 2010
Program for multiplexing of led displays for pic microcontrollers
then you can go with the following approch
use BCD to 7 segment converter, so that only 4 bits can be used to control a single 7 seven segment display..... so in total u need 12 output lines. you can get 12 output bits by using 2 different ports of any suitable 8 bit microcontroller. link to one such converter http://www.ee.washington.edu/stores/Dat
use 7 bits from one port for all 3 displays and use 3 other bits to select led's this is done very fast so human eye can not make out that the displays are glowing sequencially and not continously.
here is sample code for pic
#include
#include
void DisplayNumber( unsigned int number );
void main()
{
trisb = 0;
trisa = 0xFF;
unsigned int randNumb = 0;
while( 1 )
{
while( porta.0 == 0 ) // wait for key pressed
DisplayNumber( randNumb ); // display number to keep display refreshed
// while key pressed increment counter
// Number will be random based on how long input is turned on
while( porta.0 == 1 )
{
randNumb++;
if( ++randNumb > 9999 )
randNumb = 0;
}
// display a series of random numbers so it looks like we are
char j;
for( j = 0; j < x =" rand();" i =" 0;" i =" 0x01;" i =" 0b1000;">>= 1 )
{
digit = number % 10;
number /= 10;
portb = digit & 0x0F;
portb = (digit & 0x0F) | (i <<>
Nov 28, 2008
Assembly program for a real time clock
Code:
LCALL 061D
AGAIN MOV DPTR, #2845
REPEAT DEC82 ; Decrement DPL
MOVX A,@DPTR
MOV R3,A
MOV R5,#02
LCALL 059E
MOV A,20
LCALL 2006
MOVA,82
CJNE A,#42; REPEAT (ED)
MOVA,#OD ; OD = ASCII FOR ENTER
LCALL 2006
LJMP; AGAIN ( 6003 )
To change the RTC
2844-hrs
2843-minutes
2842-seconds
Jul 28, 2008
Interfacing Multimedia card with ATMega 128
hears some routine. Take a Look on them
void SPI_init(void)
{
DDRB |= (1 << SPICS); // 0 set port B SPI chip select to output
DDRB |= (1 << SPICLK); // 1 set port B SPI clock to output
DDRB |= (1 << SPIDO); // 2 set port B SPI data out to output
DDRB &= ~(1 << SPIDI); // 3 set port B SPI data input to input
SPCR = (1 << SPE) | (1 << MSTR); //pg#168(391)
SPICS_ON();
}
char Command(char befF, int AdrH, int AdrL, char CRC )
{ // sends a command to the MMC
SPI(0xFF);
SPI(befF);
SPI((AdrH >> 8));
SPI(AdrH);
SPI((AdrL >> 8));
SPI(AdrL);
SPI(CRC);
SPI(0xFF);
return SPI(0xFF); // return the last received character
}
unsigned char SPI(unsigned char mydata)//transmit through SPI data out
line(MOSI)
{
//unsigned char Rx_SPDR=0xDC, Rx;
SPDR = mydata; //1 Byte data
while(!(SPSR & (1<<SPIF))) // wait for complete transmission
;
//printf("\r\nRx_SPDR = 0x%X", Rx_SPDR);
//Rx=SPDR;
//printf("\r\nRx_SPDR = 0x%X", Rx_SPDR);
return SPDR; //return the received value of SPDR
}
int Read_from_MMC(void) { // send 512 bytes from the MMC via the serial port
int i;
// 512 byte-read-mode
if (Command(0x51,0,512,0xFF) != 0)
{
printf("MMC: read error 1 ");
return 0;
}
// wait for 0xFE - start of any transmission
// ATT: typecast (char)0xFE is a must!
while(SPI(0xFF) != (char)0xFE);
for(i=0; i < 512; i++)
{
while(!(UCSR0A & (1 << UDRE0))); // wait for serial port
/*Here we are transmitting 0xFF through MOSI and then assigning the received
character to USART Data Register*/
UDR0 = SPI(0xFF); // send character
}
// at the end, send 2 dummy bytes
SPI(0xFF); // actually this returns the CRC/checksum byte
SPI(0xFF);
return 1;
}
You might be also interested in:
:: Assembly Language Programs for Multiplication and Division
:: Assembly Language Programs on array of Hexadecimal numbers
:: Assembly Language Programs on strings
Jul 26, 2008
A C program for serial communation with pc using 8051
This is the subroutine or function in c for accept line from serial port
void get_line(void)
{
char c, index=0;
while(c = getchar() != '\n')
{
buffer[index++] = c;
}
}
The main program
void main()
{
PCON = 0x80; // Double Baud Rate
SCON = 0x50; // SCON: mode 1, 8-bit UART, enable rcvr
TMOD |= 0x20; // TMOD: timer 1, mode 2, 8-bit reload
TH1 = BAUD_CONST; // TH1: reload value for desired baud. Calculate this for your crystal frequency
TR1 = 1; // TR1: timer 1 run
TI = 1;
RI = 0;
get_line(); //function call
}
You might be also interested in:
:: options available for int 21h instruction
:: Answers of Microprocessor(8085) & Electronics FAQ
:: The 8085 Microprocessor Architecture Microprocessors & Interfacing
May 13, 2008
TCP/IP on PIC 18 series
implement the tcp/ip or udp port in your projects using ENC28j60 from microchip, using SPI port
or try this
Go to www.microchip.com and search for
PIC18F97J60
It comes with ready TCP IP stack and it will help you...let me know if you need further information...
You might be also interested in:
:: 8051 based project for electrical students
:: free and open source 8086 Microprocessor Emulator
:: Invoke function