jayanth.devarayanadurga
Banned
- Joined
- Dec 4, 2012
- Messages
- 4,280
- Helped
- 822
- Reputation
- 1,654
- Reaction score
- 791
- Trophy points
- 1,393
- Location
- Bangalore, India
- Activity points
- 0
# define LDE PORTB,0
BSF LED
BCF LED
led equ 0x01
BSF PORTB,led
Code C - [expand] 1 2 3 4 5 6 7 8 #define LED LATAbits.LATA0 void led_toggle(){ asm("bsf LED"); asm("bcf LED"); }
Code C - [expand] 1 2 asm("movlw 0x00"); asm("movwf PORTA");
Code C - [expand] 1 2 3 #define LED LATAbits.LATA0 asm("bsf LED");
Code C - [expand] 1 2 3 #define LED LATD,0 asm("bsf LED);
list p=16f628A ; list directive to define processor
#include <p16F628A.inc> ; processor specific variable definitions
errorlevel -302 ; suppress message 302 from list file
__CONFIG _CP_OFF & _CPD_OFF & _LVP_OFF & _BOREN_ON & _MCLRE_OFF & _WDT_ON & _PWRTE_ON & _HS_OSC
;***** PIN DEFINITIONS
#define BEEP PORTA,0 ;Output
#define HITAG_GREEN PORTA,1 ;Input, low when tag present
#define HITAG_CTS PORTA,2 ;Input, low when Hitag accepting commands
#define DATA_TO_HITAG PORTA,3 ;Output, 9600 bauds data to Hitag module
#define DEBUGPIN PORTA,4 ;note OD output!
#define DATA_FROM_HITAG PORTB,0 ;Input, 9600 bauds data from Hitag module
#define RX PORTB,1 ;Input, 38,400 bauds data from host
#define TX PORTB,2 ;Output, 38,400 bauds data to host
#define BUS_EN PORTB,3 ;Output, high to enable bus transmitter
#define MBX PORTB,4 ;Input, low when mailbox lid lifted
#define DOORBELL PORTB,5 ;Input, low when doorbell button is pressed
#define GATE_LED PORTB,6 ;Output, high to enable gate LED
#define UNLOCK PORTB,7 ;Output, high to open the gate lock
main
clrf Events
clrf HWStatus
bcf UNLOCK ;must be locked at power up.
clrf RelockTimer
clrf BeepTimer ;silent at power up
clrf BellLockoutTimer
bcf GATE_LED ;light off at power up
call BusTxPrepare
movlw BusRxBuffer
movwf BusRxPtr ;point to start of buffer
call HitagSetup
But why? Code size will be just the same for well considered C code.I want to replace all c doe inside the functions with asm code.
LCD_Out(4,1,"Working?");
asm("bsf LED");
while(1)
{
asm("clrwdt");
}
return (0);
#include <xc.h>
#include "eeprom_routines.h"
#include <string.h>
#include <stdio.h>
#pragma config FOSC=HS, WDTE=ON, PWRTE = ON, MCLRE_ON, CP=OFF, CPD=OFF, BOREN=ON, CLKOUTEN=OFF, IESO=OFF, FCMEN=OFF
#pragma config WRT=OFF, PLLEN=OFF, STVREN=ON, BORV=HI, LVP=OFF
//***** SYSTEM CONSTANTS
#define _XTAL_FREQ 19660800
#define BaudRate 38400
#define BRGVALUE (_XTAL_FREQ / (BaudRate * 64)) -1 //for BRGH = 0
//***** PIN DEFINITIONS
#define CLK5730 PORTAbits,RA0 //Output, clock to STV5730
#define CSN5730 PORTAbits,RA1 //Output, active low select to STV5730
#define DATA5730 PORTAbits,RA2 //Output, data to STV5730
#define SPARE0 PORTAbits,RA3 //Output,
#define SPARE1 PORTAbits,RA4 //Output,
#define NC1 PORTAbits,RA5 //Unavailable - used for -MCLR
#define NC2 PORTAbits,RA6 //Unavailable - used for XTAL
#define NC3 PORTAbits,RA7 //Unavailable - used for XTAL
#define SPARE2 PORTBbits,RB0 //Output,
#define RX PORTBbits,RB1 //Input, 38,400 bauds data from host
#define TX PORTBbits,RB2 //Output, 38,400 bauds data to host
#define SPARE3 PORTBbits,RB3 //Output,
#define SPARE4 PORTBbits,RB4 //Output,
#define CLK459 PORTBbits,RB5 //Output, SPI clock to MAX459
#define CSN459 PORTBbits,RB6 //Output, active low select to MAX459
#define DATA459 PORTBbits,RB7 //Output, data to MAX459
//***** 8-bit transfers to SPI devices
void SPI_OSD8(char SPIDataL)
{
char Clocks = 7;
unsigned char BitMask = 0x80;
CSN5730 = 0;
do
{
CLK5730 = 0; //SPI clock low while data changes
if(BitMask & SPIDataL) DATA5730 = 1; //set or reset SPI data line
else DATA5730 = 0;
BitMask /= 2;
CLK5730 = 1; //SPI clock high to latch data bit
}while(Clocks-- != 0);
CSN5730 = 1; //ensure devices are deselected
}
The question can be rephrased:What about asm("bsf LED"); ??
Why is it not working?
The post in microchip forum gives a plausible explanation why asm("bsf LED"); doesn't work.I saw those answers at microchip but that #asm and #endasm thing gives error in my XC8 Compiler. I don't know why.
Knowing how to "do it in ASM" is one thing (Read the XC8 User's Guide). Knowing whether it is worthwhile making your program less portable and less maintainer-friendly by (interspersing the C code with Assembler instructions) is another.
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?